I have a vector (I actually just retrieved individual columns from a dataframe) which has missing data in it. I want to replace the missing data with the next available data
I want to add a next solution which using the runner
r cran package.
library(runner)
> fill_run(data, run_for_first = T)
[1] 5 5 5 5 5 5 5 7 7 7
> rev(fill_run(rev(data), run_for_first = T))
[1] 5 5 5 5 5 7 7 7 7 7
The whole package is optimized and major of it was written in cpp. Thus offer a great efficiency.
Maybe use na.locf
...?
library(zoo)
na.locf(na.locf(zoo(data),fromLast = TRUE,na.rm = FALSE),na.rm = FALSE)
1 2 3 4 5 6 7 8 9 10
5 5 5 5 5 7 7 7 7 7