Re: [R] without a loop

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Wed 08 Jun 2005 - 01:14:55 EST

On Tue, 7 Jun 2005 11:02:13 -0400 Omar Lakkis 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?

Package zoo contains a generic function na.locf (last observation carried forward) which handles this:

R> tmp <- c(-1,NA,NA,1,1,NA,NA,1)
R> library(zoo)
R> na.locf(tmp)

[1] -1 -1 -1 1 1 1 1 1

Z

> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 08 01:23:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:27 EST