I am trying to calculate the mean of two variables and outputting it as a new variable. For example:
data$Average <- (data$Visit1 + data$Visit2) / 2
However, there are NA values for both 'Visit 1' and 'Visit 2' variables across the dataset.
How can I write some code such that I am able to identify if NA values exist in either Visit 1 or 2, then I would use the corresponding row's values but for 'Visit 3' and 'Visit 4' instead, to calculate the average?
Many thanks!
Aucun commentaire:
Enregistrer un commentaire