I have created the variable np_collpar with the following code
a <- c(NA,NA,NA,1,1,1)
c1 <- c(9,3,NA,NA,NA,5)
c2 <- c(5,NA,NA,NA,5,2)
c3 <- c(3,7,NA,NA,NA,9)
df <- data.frame(a,c1,c2,c3)
np_collpar <- ifelse(a==1 & (!is.na(c1) | !is.na(c2) | !is.na(c3)),1,0)
I want np_collpar to be 1 for rows 5 and 6 and 0 for rows 1-4. However, NA is returned for rows 1 and 2. The Boolean reasoning behing the ifelse statement should be correct. Could anyone give me a hint? Thanks.
Aucun commentaire:
Enregistrer un commentaire