[R] without a loop

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jun 7 17:19:22 CEST 2005


On 6/7/05, Omar Lakkis <uofiowa at gmail.com> wrote:
> tmp <- c(-1,NA,NA,1,1,NA,NA,1)
> 
> without using a loop, how can I replace all NAs in the list above with
> the previous none NA value in the list?

This is known as last occurrence carried forward (LOCF) and
is implemented in both the 'zoo' and 'its' packages, e.g.

library(zoo)
na.locf(tmp)




More information about the R-help mailing list