[R] Interpolating spline problems and akima

From: Tom C Cameron <bgytcc_at_leeds.ac.uk>
Date: Wed 25 Jan 2006 - 21:56:46 EST


Hi everyone

I was using spline to interpolate single or two consecutive missing data points in time series. However, when it comes to longer gaps in the data the spline function generate new data for both my known and unknown data (see below).

Aside from not understanding why this happens, I thought thought I might try function "aspline" in library (akima). However, I cannot install or find this library/package.

Has anyone any instructions to install this package or help with my problem?

Using this works....

> day<-c(1,2,3,4,5,6,7,8,9,10,11,12,13)
> datfile<-c(16,23,39,37,45,34,NA,3,7,8,15,20,21)
> for (i in 1:13) {

+ dat<-datfile
+ dat.ok <- !is.na(dat)
+ dat2<-dat[dat.ok]
+ day2<-day[dat.ok]
+
+ dat.interp<-spline(day2,dat2,length(day))
+ outt<-rep(NA,length(day))
+ for (j in 1:length(dat.interp$x)) {
+ outt[j]<-dat.interp$y[j]
+ } }

but this does not....?

> day<-c(1,2,3,4,5,6,7,8,9,10)
> datfile<-c(17,6,29,22,90,72,20,4,4,NA)
> for (i in 1:10) {

+ dat<-datfile
+ dat.ok <- !is.na(dat)
+ dat2<-dat[dat.ok]
+ day2<-day[dat.ok]
+
+ dat.interp<-spline(day2,dat2,length(day))
+ outl<-rep(NA,length(day))
+ for (j in 1:length(dat.interp$x)) {
+ outl[j]<-dat.interp$y[j]
+ } }
...........................................................................
Dr Tom C Cameron                        office: 0113 34 32837 (10.23 Miall)
Ecology & Evolution Res. Group.         lab: 0113 34 32884 (10.20 Miall)
School of Biological Sciences           Mobile: 07966160266
University of Leeds                     email: t.c.cameron@leeds.ac.uk
Leeds LS2 9JT
LS2 9JT

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 Wed Jan 25 22:08:49 2006

This archive was generated by hypermail 2.1.8 : Thu 26 Jan 2006 - 02:10:17 EST