r - Apply any over rows -
in r any-function applied on columns result boolean. best way, apply row row? target in case recode a, if of a, b or c 1 or 6. (if true test$new should 101)
here dataframe:
b c d 1 1 1 "a" 2 1 2 "b" 3 6 3 "c" 5 3 5 "d"
it done in way, there should smarter solution:
test$new <- ifelse(test$a == 1 | test$b == 1 | test$c == 1 | test$a == 6 | test$b == 6 | test$c == 6, 101, na)
test$new <- ifelse(apply(test,1,function(x) any(x==1|x==6)),101,na)
r
No comments:
Post a Comment