[R] replacing NA's with various numbers

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 6 04:58:03 CEST 2007


On 10/5/07, Leeds, Mark (IED) <Mark.Leeds at morganstanley.com> wrote:
> x[is.na(x)]<- y[is.na(x)] but this will only work correctly if x and y
> are the same length so I hope that is
> what you mean by the same style.


That can be fixed if y is at least as long as to reach the last NA
in x like this:

x[is.na(x)] <- y[which(is.na(x))]



More information about the R-help mailing list