If I use the na.locf function to replace each NA with the most recent
non-NA prior to it, then

> na.locf(c(NA,NA,1,4,NA,2))
[1] 1 1 1 4 4 2

I want to keep leading NA's, and this is what I want
 NA NA 1 4 4 2

How can I do it?

The following do not work:

> na.locf(c(NA,NA,1,4,NA,2), na.rm=FALSE)
Error in na.locf(c(NA, NA, 1, 4, NA, 2), na.rm = FALSE) :
  unused argument (na.rm = FALSE)
> na.locf(c(NA,NA,1,4,NA,2), na.rm=TRUE)
Error in na.locf(c(NA, NA, 1, 4, NA, 2), na.rm = TRUE) :
  unused argument (na.rm = TRUE)


Thank you very much!

John

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to