I'm trying to make a variable in R that is an average of 4 other variables; however, there is a missing value for one observation in one of the variables. Thus, the average value is missing for this observation.
I would like to have this observation's value for the new average variable be the average of the three variables that this observation has data on.
Here is the code that I'm using now:
data$average <- (data$var1+data$var2+data$var3+data$var4)/4