Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-08 Thread Charles C. Berry
and retains the grouping column (the first) while your original code returns a matrix without the grouping column. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent:

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-08 Thread Dimitri Liakhovitski
y(names.used, function(x){ >>>        unlist(by(frame, frame$group, function(y) y[,x] / >>> mean(y[,x],na.rm=T))) >>>        })) >>> }) >>> # Took me 1.25-1.32 min >>> ############### >>> >>> ### METHOD 6 -

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Dimitri Liakhovitski
;- do.call(cbind, lapply(names.used, function(x){ >>>        unlist(by(frame, frame$group, function(y) y[,x] / >>> mean(y[,x],na.rm=T))) >>>        })) >>> }) >>> # Took me 1.25-1.32 min >>> ################### >>> >>> #

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Tom Short
# >> frame<-ORIGframe >> library(plyr) >> function3 <- function(x) x / mean(x, na.rm = TRUE) >> system.time({ >> grouping.factor<-"group" >> myvariables<-names(frame)[2:8] >> frame3<-ddply(frame, grouping.factor, colwise(fun

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Dimitri Liakhovitski
lt;-ORIGframe >> >> system.time({ >> >> frame <- do.call(cbind, lapply(names.used, function(x){ >> >>        unlist(by(frame, frame$group, function(y) y[,x] / >> >> mean(y[,x],na.rm=T))) >> >>        })) >> >> }) &

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Rob Forler
## > >> > >> ### METHOD 6 - the slowest; using "plyr" and > >> "ddply":## > >> frame<-ORIGframe > >> library(plyr) > >> function3 <- function(x) x / mean(x, na.rm = TRUE) > >

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Dimitri Liakhovitski
Gframe >> library(plyr) >> function3 <- function(x) x / mean(x, na.rm = TRUE) >> system.time({ >> grouping.factor<-"group" >> myvariables<-names(frame)[2:8] >> frame3<-ddply(frame, grouping.factor, colwise(function3, myvariables)) >> }) >>

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Tom Short
nction(frame) { >>   for(i in 2:ncol(frame)) { >>      frame[,i] <- ave(frame[,i], frame[,1], >> FUN=function(x)x/mean(x,na.rm=TRUE)) >>   } >>   frame >> } >> >> Note that this returns a data.frame and retains the >> grouping column (the first)

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-04-07 Thread Dimitri Liakhovitski
are > wdunlap tibco.com > >> -----Original Message----- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter >> Sent: Tuesday, March 30, 2010 10:52 AM >> To: 'Dimitri Liakhovitski'; 'r-help'

Re: [R] Code is too slow: mean-centering variables in a data framebysubgroup

2010-03-31 Thread William Dunlap
rch 30, 2010 10:52 AM > To: 'Dimitri Liakhovitski'; 'r-help' > Subject: Re: [R] Code is too slow: mean-centering variables > in a data framebysubgroup > > ?scale > > Bert Gunter > Genentech Nonclinical Biostatistics > > > > -Origina