r - Populate NAs in a vector using prior non-NA values? -
r - Populate NAs in a vector using prior non-NA values? -
what's compact/efficient way populate nas using prior non-na value? example:
test = c( 1 , 2 , na , na , 5 , na , 9 , na , na ) expected = c( 1 , 2 , 2 , 2 , 5 , 5 , 9 , 9 , 9 )
here, of na values 'look back' first non-na value. i'm trying avoid loop
library(zoo) na.locf(test) [1] 1 2 2 2 5 5 9 9 9
r
Comments
Post a Comment