Thomas Petzoldt <[EMAIL PROTECTED]> writes:

> 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?

I wouldn't know about efficiency, but the last bit of code is
equivalent to

app <- lapply(x[-1], approx, x=x$time, xout=t)
data.frame(time=t,lapply(app,"[[","y"))

which should at least be somewhat easier to read...

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to