[R] Interpolating spline problems and akima
Tom C Cameron
bgytcc at leeds.ac.uk
Wed Jan 25 11:56:46 CET 2006
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 at leeds.ac.uk
Leeds LS2 9JT
LS2 9JT
More information about the R-help
mailing list