Hi Mohamed, Thx for the answer. And what should I do if my fun function is not 'sum' but 'max'? Bert -----Original Message----- From: Mohamed Lajnef [mailto:mohamed.laj...@inserm.fr] Sent: 17 February 2010 10:02 To: Bert Jacobs Cc: r-help@r-project.org Subject: Re: [R] Is the aggregate function the best way to do this?
Hi Bret, Try to use rowSums function Regrads M Bert Jacobs a écrit : > Hi, > > > > I'm having a dataframe 'Subset1' with a number of factor variables and 160 > numerical variables > > Now I want to make sums for all rows that have the same values for the > different factor variables, except for the factor variables: VAR1,VAR2,VAR3 > who may have the same values. > > With the formula given below this works great, but in a situation with 15000 > rows and 13 factor variables the calculation takes more than 2 minutes. > > So my question is: Does anyone knows if there exists a faster alternative? > > > > Subset1.AGG <- > as.data.frame(aggregate(Subset1[,(ncol(Subset1)-159):ncol(Subset1)], > list(VAR1 = Subset1$VAR1,VAR2=Subset1$VAR2,VAR3 = Subset1$VAR3), FUN=sum) ) > > > > Thank you very much for helping me out, > > Bert > > > [[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. > > -- Mohamed Lajnef,IE INSERM U955 eq 15 Pôle de Psychiatrie Hôpital CHENEVIER 40, rue Mesly 94010 CRETEIL Cedex FRANCE mohamed.laj...@inserm.fr tel : 01 49 81 31 31 (poste 18470) Sec : 01 49 81 32 90 fax : 01 49 81 30 99 ______________________________________________ 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.