Re: [R] how to replace NA with previous numbers

2008-11-19 Thread Jorge Ivan Velez
Dear Jeff, Take a look at this post: http://www.nabble.com/replacing-Na%27s-in-a-vector-with-the-preceding-integer-element-td20484941.html#a20484941 HTH, Jorge On Wed, Nov 19, 2008 at 10:59 PM, jeffc <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a vector with lots of NAs. e.g. > vec = c(NA,

Re: [R] how to replace NA with previous numbers

2008-11-19 Thread Gabor Grothendieck
See na.locf in the zoo package. On Wed, Nov 19, 2008 at 10:59 PM, jeffc <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a vector with lots of NAs. e.g. > vec = c(NA, NA, 2, NA, NA, 5, NA, 6, NA) >> vec > [1] NA NA 2 NA NA 5 NA 6 NA > > I would like to replace NAs with their immediately previous n

[R] how to replace NA with previous numbers

2008-11-19 Thread jeffc
Hi, I have a vector with lots of NAs. e.g. vec = c(NA, NA, 2, NA, NA, 5, NA, 6, NA) > vec [1] NA NA 2 NA NA 5 NA 6 NA I would like to replace NAs with their immediately previous non NA number. After replacement, the above vector will become > vec [1] 0 0 2 2 2 5 5 6 6. I understand how to