I have a dataframe like this:
a <- c(1:9)
b <- as.factor(c("Day", "Day", NA, "Night", NA, "Day", NA, "Night", "Night"))
df<-data.frame(a=a,b=b)
I would like to conditionally replace the NA values, based on the values that already exist, in order to create this:
df$a <- c(1:9)
df$b <- as.factor("Day", "Day", "Dusk", "Night", "Dawn", "Day", "Dusk", "Night", "Night")
I've explored using na.locf() and fill() but haven't quite managed to figure out a solution yet.