[I replied to Gabor only, I think i may be interesting to cc the list, for the record.]
---------- Forwarded message ---------- From: bruno Piguet <bruno.pig...@gmail.com> Date: 2010/6/29 Subject: Re: [R] Fast and simple tool for re-sampling of asynchronous time series ? To: Gabor Grothendieck <ggrothendi...@gmail.com> 2010/6/25 Gabor Grothendieck <ggrothendi...@gmail.com> > > The apply statements often have minimal performance advantage -- they > are more for eliminating certain bookkeeping operations associated > with loops and making the code more compact. > In this case, the real speed-up solution was a change in algorithm. If time values are sorted (which is not a too unrealistic hypothesis), one doesn't need to re-scan the whole vector to find the values close to the next sample. So, I eventually coded in R just as in C ou Fortran : Y_sync <- rep(NA, length(Tx)) jmax <- length(Ty) j0 <- 1 for (i in 1:length(Tx)) { T_min <- Tx[i] - w T_max <- Tx[i] + w while ( j0<=jmax & Ty[j0] < T_min ) j0 = j0 + 1 if (j0 > jmax) Y_sync[i] <- NA else { j1 <- j0 while ( j1<=jmax & Ty[j1] <= T_max) j1 = j1 + 1 Y_sync[i] <- mean(Y[j0:(j1-1)]) } } which gives something fast enough and simple enough for my current needs. Bruno. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.