Re: [R] efficient rolling rank

2010-04-18 Thread zerdna
Gabor, Charles, Whit -- i've been walking the woods of R alone so far, and i got to say that your replies to that trivial question are eye-opening experience for me. Gentlemen, what i am trying to say in a roundabout way is that i am extremely grateful and that you guys are frigging awesome. Let

Re: [R] efficient rolling rank

2010-04-18 Thread Gabor Grothendieck
Looks like the rank function in R takes up most of the time. Replacing it with a sum reduces the time of the rollapply solution to one sixth of the its original time: system.time(rollapply(z,len, function(x) rank(x)[len])) user system elapsed 17.000.27 17.27

Re: [R] efficient rolling rank

2010-04-18 Thread Charles C. Berry
On Sun, 18 Apr 2010, zerdna wrote: Gabor, Charles, Whit -- i've been walking the woods of R alone so far, and i got to say that your replies to that trivial question are eye-opening experience for me. Gentlemen, what i am trying to say in a roundabout way is that i am extremely grateful and

Re: [R] efficient rolling rank

2010-04-17 Thread Whit Armstrong
library(fts) x - fts(data=rnorm(1e6)) system.time(xrnk - moving.rank(x,500)) user system elapsed 0.680.000.68 you will have to disguise your data as a time series to use fts. see below the exact implementation of rank that is used. -Whit templatetypename ReturnType class

[R] efficient rolling rank

2010-04-16 Thread zerdna
Could someone give me an idea on how to do rolling ranking, i.e. rank in the moving window of last 100 numbers in a long vector? I tried naive solution like roll.rank-function(v, len){ r-numeric(length(v)-len+1) for(i in len:length(v)) r[i-len+1]-rank(v[(i-len+1):i])[len] r

Re: [R] efficient rolling rank

2010-04-16 Thread Gabor Grothendieck
I don't know if its any faster but you could try: library(zoo) z - zoo(v) rollapply(z, len, function(x) rank(x)[len]) On Fri, Apr 16, 2010 at 4:21 PM, zerdna az...@yahoo.com wrote: Could someone give me an idea on how to do rolling ranking, i.e. rank in the moving window of last 100 numbers

Re: [R] efficient rolling rank

2010-04-16 Thread Charles C. Berry
On Fri, 16 Apr 2010, zerdna wrote: Could someone give me an idea on how to do rolling ranking, i.e. rank in the moving window of last 100 numbers in a long vector? I tried naive solution like roll.rank-function(v, len){ r-numeric(length(v)-len+1) for(i in len:length(v))