[R] Replacing NAs with interpolated values
Torsten Hothorn
Torsten.Hothorn at rzmail.uni-erlangen.de
Wed Sep 5 16:43:52 CEST 2001
> Hi there,
>
> I've got this vector:
>
> -84 -87 -90 -90 -89 -86 NA NA NA NA NA NA NA NA NA NA NA NA -96
> -99 -100 -99 -96 -92 -89 -87 -87 -88 -90 -92 -94 -95 -96
> -97 -97 -97 -96 -95
>
> Is there a function in R which replaces the NAs with "interpolated"
> values between -86 and -96?
maybe something like
> x <- c(1,2,NA, NA, NA, 10)
> indx <- which(is.na(x))
> x[is.na(x)] <- mean(c(x[indx[1]-1], x[indx[length(indx)]+1]))
> x
[1] 1 2 6 6 6 10
where `mean' is to be replaced with your interpolation :-)
Torsten
>
> Thanks, Sven
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list