[R] replacing Na's in a vector with the preceding integer element

From: ravi <rv15i_at_yahoo.se>
Date: Thu, 13 Nov 2008 17:07:35 +0000 (GMT)


Hi,
I have a vector where an integer is followed by a randomly varying number of NA elements. I want to replace the NA's with the preceding integer. Let me explain with a simple example : avec<- c(1,NA,NA,5,NA,3,4,NA,NA,NA,NA,9,NA,0,NA,NA) I want to get the following vector from a : bvec<-c(1,1,1,5,5,3,4,4,4,4,4,9,9,0,0,0)

How can I do this with R? Will appreciate all the help that I can get. Thanking you,
Ravi



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 13 Nov 2008 - 17:09:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Nov 2008 - 17:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive