I have a data frame containing a variable with interspersed NAs.
I want to replace/ create a new variable replacing the NAs with the last non-NA value...I've been trying to come up with a
dplyr::mutate consturction, but maybe a base R soln is better.
in any case I'm blocked up on this and would appreciate any help. see examples below:
df_i_have <- data.frame(obs = LETTERS[1:10], value = c(1:3, NA, NA, 4:5, NA, 6:7)) df_i_want <- data.frame(obs = LETTERS[1:10], value = c(1:3, 3, 3, 4:5, 5, 6:7))
Created on 2018-11-12 by the reprex package (v0.2.1)