Let's say I have this column.
dataframe$column<-c(1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, NA, NA, 0)
and I got this vector
vector<- c(1, 5, 9)
I need to create a new column in my data frame that would return 0 when the value in any given row is equal to any value of my vector. If it is not equal I would like to return a 0, and if the column originally had a NA, I would like to return a NA as well.
So in my example the new colum should look like this:
[1] 1 0 0 0 0 0 0 1 1 1 0 0 0 1 NA NA 0
I'm pretty sure I could do this with apply or sapply, but I'm not very good with loops.
Thanks in advance.