Replacing missing data in vector with existing data

前端 未结 2 752
猫巷女王i
猫巷女王i 2020-12-06 22:46

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

2条回答
  •  无人及你
    2020-12-06 23:08

    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.

提交回复
热议问题