I am stuck in one problem and try to find the similar solution but was unable to find that here in stackoverflow. My data look like this:
x1 <- data.frame(x = c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0))
y1 <- data.frame(x = c(sin(x1 - 3.4)), y = c(cos(x1-3.2), z = tan(x1-3.5)))
What I want to do is to replace the value of y1 by NA if x1 = 0 but would like to keep the value as it is if x1 = 1 for whole data frame y1 at the same time. I
I tried ifelse function as
y1 <- ifelse(x1 == 0, NA, y1)
But I was unable to process that. If anyone can suggest me the answer without loop that would be great.
Thanks in advance
y1[x1==0,]=NA(NA^!x1)*y1