Populate NAs in a vector using prior non-NA values?

后端 未结 1 1167
长情又很酷
长情又很酷 2020-12-11 07:23

What\'s a compact/efficient way to populate NAs using the prior non-NA value? For example:

test = c( 1 , 2 , NA , NA , 5 , NA , 9 , NA , NA )
expected = c(          


        
相关标签:
1条回答
  • 2020-12-11 07:52
    library(zoo)
    na.locf(test)
    [1] 1 2 2 2 5 5 9 9 9
    
    0 讨论(0)
提交回复
热议问题