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
Any advice will be appreciated.