I am trying to create new column by condition, where if value in A equal to 1, value is copied from B column, otherwise from C column. When A has NA, condition does not work. I dont want to drop this NA and do following: If A contains NA, values has to taken from C column
df <- data.frame (A = c(1,1,NA,2,2,2),
B = c(10,20,30,40,25,45),
C = c(11,23,33,45,56,13))
#If Customer faced defect only in Wave_3 his Boycotting score is taken from wave 3, otherwise from wave 4
df$D1 <- ifelse(df$A ==1 , df$B ,df$C)
Expected output:
