[R] efficient matrix approx

Thomas Petzoldt petzoldt at rcs.urz.tu-dresden.de
Thu Feb 19 18:29:27 CET 2004


Hello,

I am looking for a highly efficient matrix version of linear
interpolation (like approx). As an example I have data like follows:

x<-data.frame(time=1:20, x=(1:20)/10, y=runif(20))
t <- seq(1.5, 15.5 ,by=0.5)

# and I found the following solution:

nam <- names(x)
app <- lapply(x[2:3],approx,x=x$time, xout=t)
r <- c(1, 2*(1:(ncol(x)-1)))
x.new <- as.data.frame(unlist(app[1:2], recursive=F)[r])
names(x.new) <- nam


As this routine should be called several times during an optimization
procedure I wonder if there is a more direct one which I have overlooked?

Thank you in advance

Thomas P.




More information about the R-help mailing list