This is the data:
a = c(1,0,0,NA,0,1)
b = c(0,1,0,NA,NA,0)
c = c(0,1,0,NA,NA,NA)
cbind(a,b,c) -> df
I want to generate a variable named x. It needs the following requirements:
- As long as there is one ‘1’ in the three lines,
xis ‘1’; otherwisexis ‘0’. - Only when all three lines are missing and does not have a ‘1’,
xis returned as a missing value,NA.
df
a b c x
[1,] 1 0 0 1
[2,] 0 1 1 1
[3,] 0 0 0 0
[4,] NA NA NA NA
[5,] 0 NA NA NA
[6,] 1 0 NA 1