Re: [R] Help with ddply to eliminate a for..loop

2010-08-26 Thread Ista Zahn
A ddply solution is dat.out <- ddply(dat, .(time), transform, slope = scale(slope)) but this is not faster than the loop, and slower than the ave() solution: > system.time( + for (i in 1:3) { +mat <- dat[dat$time==i, ] +outi <- data.frame(mat$time, mat$id, slope=scale(mat$slope)) +if

Re: [R] Help with ddply to eliminate a for..loop

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 4:33 PM, Bos, Roger wrote: > I created a small example to show something that I do a lot of.  "scale" > data by month and return a data.frame with the output.  "id" represents > repeated observations over "time" and I want to scale the "slope" > variable.  The "out" variabl

Re: [R] Help with ddply to eliminate a for..loop

2010-08-26 Thread Marc Schwartz
On Aug 26, 2010, at 3:40 PM, Marc Schwartz wrote: > On Aug 26, 2010, at 3:33 PM, Bos, Roger wrote: > >> I created a small example to show something that I do a lot of. "scale" >> data by month and return a data.frame with the output. "id" represents >> repeated observations over "time" and I wa

Re: [R] Help with ddply to eliminate a for..loop

2010-08-26 Thread Marc Schwartz
On Aug 26, 2010, at 3:33 PM, Bos, Roger wrote: > I created a small example to show something that I do a lot of. "scale" > data by month and return a data.frame with the output. "id" represents > repeated observations over "time" and I want to scale the "slope" > variable. The "out" variable sh

[R] Help with ddply to eliminate a for..loop

2010-08-26 Thread Bos, Roger
I created a small example to show something that I do a lot of. "scale" data by month and return a data.frame with the output. "id" represents repeated observations over "time" and I want to scale the "slope" variable. The "out" variable shows the output I want. My for..loop does the job but is