[R] Help with interpolation

Bert Gunter gunter.berton at gene.com
Thu May 13 18:13:26 CEST 2010


... and what package is interpNA in, pray tell? (Such information is
requested in the posting guide).

Base R does it with a bit of fiddling:

?approx

But please read the Help carefully. Here is a simple example of how it is
used:

> x <- 1:5
> y <- c(2,rep(NA,3),7)
> approx(x,y, xout =1:5)## Note the xout argument
$x
[1] 1 2 3 4 5

$y
[1] 2.00 3.25 4.50 5.75 7.00

So you'll have to convert your dates into a suitable numeric series using
whatever date functions you need (e.g. as.Date() ). There are, no doubt,
several packages (perhaps zoo) that can do it at one gulp.

Bert Gunter
Genentech Nonclinical Biostatistics
 
 -----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Jorge Nieves
Sent: Thursday, May 13, 2010 8:52 AM
To: R-help at r-project.org
Subject: [R] Help with interpolation



> Hi,
> 
> I have a two Colum matrix ( I named it holder) as shown bellow. It
> seems to be three columns, but the first column contains the row
> names.
> 
> I am trying to fill all  NAs by linear interpolation the known values
> in the matrix. I tried using the interpNA function, but I get an error
> message:
> 
> > interpNA(holder, method = "linear")
> Error in approx(idx, x[idx], 1:n, method = method, f = f) : 
>   need at least two non-NA values to interpolate
> In addition: Warning message:
> In xy.coords(x, y) : NAs introduced by coercion
> > 
> 
> 
> I was wondering if some one could recommend another function to get
> the interpolated values?
> 
> Thanks,
> 
> Jorge
> 
> 20100319 2010-03-19  1626
> 20100320 2010-03-20    NA
> 20100321 2010-03-21    NA
> 20100322 2010-03-22    NA
> 20100323 2010-03-23    NA
> 20100324 2010-03-24    NA
> 20100325 2010-03-25    NA
> 20100326 2010-03-26  1638
> 20100327 2010-03-27    NA
> 20100328 2010-03-28    NA
> 20100329 2010-03-29    NA
> 20100330 2010-03-30    NA
> 20100331 2010-03-31    NA
> 20100401 2010-04-01    NA
> 20100402 2010-04-02  1669
> 20100403 2010-04-03    NA
> 20100404 2010-04-04    NA
> 20100405 2010-04-05    NA
> 20100406 2010-04-06    NA
> 20100407 2010-04-07    NA
> 20100408 2010-04-08    NA
> 20100409 2010-04-09  1756
> 20100410 2010-04-10    NA
> 20100411 2010-04-11    NA
> 20100412 2010-04-12    NA
> 20100413 2010-04-13    NA
> 20100414 2010-04-14    NA
> 20100415 2010-04-15    NA
> 20100416 2010-04-16  1829
> 20100417 2010-04-17    NA
> 20100418 2010-04-18    NA
> 20100419 2010-04-19    NA
> 20100420 2010-04-20    NA
> 20100421 2010-04-21    NA
> 20100422 2010-04-22    NA
> 20100423 2010-04-23  1912
> 20100424 2010-04-24    NA
> 20100425 2010-04-25    NA
> 20100426 2010-04-26    NA
> 20100427 2010-04-27    NA
> 20100428 2010-04-28    NA
> 20100429 2010-04-29    NA
> 20100430 2010-04-30  1995
> 
> 

	[[alternative HTML version deleted]]

______________________________________________
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.



More information about the R-help mailing list