Apologies in advance if this is too basic for this community.
I have a dataframe like the one attached here. And I want to tell R to do this: B1 + B2 /2 for every missing variable in column B4, and then create (write this) a new column A1.
I have unsuccessfully attempted to resolve this using:
mydata$A1 = ifelse(mydata$B4 %in% c("NA") ,(mydata$B1 + mydata$B2) /2
I think you need to specify the last argument of ifelse, as in you need to decide what goes into A1 if the observation in B4 is not NA. Obviously EeethB's elegant solution works well too