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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -