Re: [R] interpolating a lot of data at once

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 01 Jun 2006 - 03:26:59 EST

On 5/31/06, David Hugh-Jones <davidhughjones@gmail.com> wrote:
> I have a big dataset containing a lot of values for 1970, 1980 and
> 1990. I want to interpolate values for the years in between, and also
> if possible to extrapolate to 1968 and 1969. The method doesn't have
> to be clever but I am looking for a function that will do all the data
> at once. (Doing foreach, or apply, is just too slow!) Is there
> something that will take
>
> list(df$val.1970, df$val.1980, df$val.1990)
>
> as inputs and output an interpolated matrix?
>

Here are a variety of approaches:

# 1. using lm

y.lm <- lm(y ~ tt, list(y = 1:3, tt = seq(1970, 1990, 10))) predict(y.lm, list(tt = 1968:1990))

# 2. using "ts" objects:and "dyn" package

library(dyn)
w <- ts(1:3, start = 1970, delta = 10)
w.lm <- dyn$lm(w ~ tt, list(tt = time(w))) predict(w.lm, list(tt = 1968:1990))

# if only interpolation needed using na.approx.zoo

library(zoo)
z <- zoo(1:3, c(1970, 1980, 1990))
na.approx(merge(as.zoo(z), zoo(, 1970:1990))) # ignore warning



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 01 03:33:41 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 01 Jun 2006 - 06:10:27 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.