I have the following data:
library(dplyr)
d <- data_frame(
unique = c(1,2,3,4),
lat = c(NA, 87.6, 78.6, 67.7),
latitude= c(34.5, NA, 45.6, 34.8))
What I would like to do is when there is an 'NA' in lat (for example in column 1 'lat' has an NA) the value from latitude is taken. So I would end up with a new column called 'latitude_new' that looks like (34.5, 87.6, 45.6, 34.8)
.
I'm sure this can be done using 'mutate from dplyr, I'm just not quite sure how?