if is na r code example
Example 1: r na if
dat <- dat %>% mutate(x = replace(x, x<0, NA))
Example 2: if not na in r
> apply(p, 1, function(x) which(!is.na(x)) )
[[1]]
[1] 2 3
[[2]]
[1] 4 7
[[3]]
integer(0)
[[4]]
[1] 5
[[5]]
integer(0)
dat <- dat %>% mutate(x = replace(x, x<0, NA))
> apply(p, 1, function(x) which(!is.na(x)) )
[[1]]
[1] 2 3
[[2]]
[1] 4 7
[[3]]
integer(0)
[[4]]
[1] 5
[[5]]
integer(0)