I would like to solve the following problem with dplyr. Preferable with one of the window-functions. I have a data frame with houses and buying prices. The following is an e
A dplyr
and imputeTS
combination.
library(dplyr)
library(imputeTS)
df %>% group_by(houseID) %>%
mutate(price = na.locf(price, na.remaining="keep"))
You could also replace na.locf
with more advanced missing data replacement (imputation) functions from imputeTS
. For example na.interpolation
or na.kalman
. For this just replace na.locf
with the name of the function you like.