Reputation: 45
I need to change multiple values into NA or a string value based on 3 conditions. If the value in that column is smallen than that in 0, then turn it into NA.
If that value is greater or equal to the value in column x, then change to "known".
Otherwise change to "unknown".
Right now i do this in 3 lines of code, but they are overwriting each other (because line 2 is executed after line 1 which turn other values into NA.)
Lets say i have a data set x:
a1 a2 a3 a4 a5 a6
Where a1 to a6 have 200 rows containing all kind of numeric values then i want to change the values in a6 to NA whenever they are <= 0.
I want to change every value in a6 that is bigger than the value in a3 to "known".
And every other value in a6 must be set to "uknown".
I hope this clarifies a lot!
Upvotes: 0
Views: 267
Reputation: 1388
Simple enough
a6 <- ifelse(a6 > 0,
ifelse(a6 > a3, "known", "unknown"),
NA)
Upvotes: 1