mardi 25 mai 2021

looking for R function that utilizes ifelse when there are NA

I have this data in which I require an output as shown. If a is 0 and b is 0 , then c is assigned value 0 If a is 0 and b is 1 , then c is assigned value 1 If a is 0 and b is NA , then c is assigned value 0 If a is 1 and b is NA , then c is assigned value 1

a<-c(0,0,0,1,1,1,0,1)
b<-c(1,0,0,0,1,0,NA,NA)
data<-data.frame(a,b)

data$c<-c(1,0,0,1,1,1,0,1)

Aucun commentaire:

Enregistrer un commentaire