Re: [R] Need very fast application of 'diff' - ideas?

2012-01-29 Thread R. Michael Weylandt
Have you not followed your own thread? Dirk is Mr. Rcpp himself and he gives an implementation that gives you 25x improvement here as well as tips for getting even more out of it: http://tolstoy.newcastle.edu.au/R/e17/help/12/01/2471.html Michael On Sat, Jan 28, 2012 at 12:28 PM, Kevin Ummel

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-29 Thread Kevin Ummel
Sorry, guys. I'm not active on the listserve, so my last post was held by the moderator until after Dirk's solution was posted. Excellent stuff. thanks, kevin On Jan 29, 2012, at 8:37 AM, R. Michael Weylandt wrote: Have you not followed your own thread? Dirk is Mr. Rcpp himself and he gives

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-29 Thread R. Michael Weylandt
Sorry about that -- Gmail threaded things by arrival in my mailbox, not by timestamp (surprisingly) Rcpp really is one of the coolest new things in the R ecosystem -- hope it works well for you. M On Sun, Jan 29, 2012 at 11:12 AM, Kevin Ummel kevinum...@gmail.com wrote: Sorry, guys. I'm not

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-29 Thread Martin Morgan
On 01/29/2012 08:12 AM, Kevin Ummel wrote: Sorry, guys. I'm not active on the listserve, so my last post was held by the moderator until after Dirk's solution was posted. Excellent stuff. Is 'diff' really the bottleneck in your calculations? I would have said diff was in the class of 'fast'

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Peter Langfelder
ehm... this doesn't take very many ideas. x = runif(n=10e6, min=0, max=1000) x = round(x) system.time( { y = x[-1] - x[-length(x)] }) I get about 0.5 seconds on my old laptop. HTH Peter On Fri, Jan 27, 2012 at 4:15 PM, Kevin Ummel kevinum...@gmail.com wrote: Hi everyone, Speed is the

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Hans W Borchers
R. Michael Weylandt michael.weylandt at gmail.com writes: I'd write your own diff() that eliminates the method dispatch and argument checking that diff - diff.default does. x[-1] - x[-len(x)] # is all you really need. (# you could also try something like c(x[-1], NA) - x which may be

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Dirk Eddelbuettel
On 28 January 2012 at 16:20, Hans W Borchers wrote: | R. Michael Weylandt michael.weylandt at gmail.com writes: | | I'd write your own diff() that eliminates the method dispatch and | argument checking that diff - diff.default does. | | x[-1] - x[-len(x)] # is all you really need. | (#

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Dirk Eddelbuettel
On 28 January 2012 at 11:46, Dirk Eddelbuettel wrote: | | On 28 January 2012 at 16:20, Hans W Borchers wrote: | | R. Michael Weylandt michael.weylandt at gmail.com writes: | | | | I'd write your own diff() that eliminates the method dispatch and | | argument checking that diff - diff.default

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Kevin Ummel
Thanks. I've played around with pure R solutions. The fastest re-write of diff (for the 1 lag case) I can seem to find is this: diff2 = function(x) { y = c(x,NA) - c(NA,x) y[2:length(x)] } #Compiling via 'cmpfun' doesn't seem to help (or hurt): require(compiler) diff2 = cmpfun(diff2) But

[R] Need very fast application of 'diff' - ideas?

2012-01-27 Thread Kevin Ummel
Hi everyone, Speed is the key here. I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-27 Thread R. Michael Weylandt
I'd write your own diff() that eliminates the method dispatch and argument checking that diff - diff.default does. x[-1] - x[-len(x)] # is all you really need. (# you could also try something like c(x[-1], NA) - x which may be marginally faster as it only subsets x once but you should profile to