What is a compact / efficient way to populate an NA using a value other than NA? For instance:
test = c( 1 , 2 , NA , NA , 5 , NA , 9 , NA , NA )
expected = c( 1 , 2 , 2 , 2 , 5 , 5 , 9 , 9 , 9 )
Here, all NA values “look back” at the first value other than NA. I am trying to avoid the for loop
source
share