Overwriting data in Rstudio

Asked

Viewed 32 times

1

I’m new to programming in R and I have a problem. I have two columns (X and Y, respectively), in the first I have a series of values, where some are negative and I need a function that for each negative value in X, replaces the value in Y by 0. If anyone can help me, I’d appreciate it!

1 answer

1

An example to be clearer.

p <- rnorm(10000)
p[p<0] <- 0

A function:

trocaNegativo <- function(x) { x[x<0] <- 0; x }
trocaNegativo(p)

In your Cup, you can put a clause and filter out what you want in this Cup.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.