On Mar 25, 2012, at 12:27 , Gabor Grothendieck wrote: > 2012/3/25 Skála, Zdeněk (INCOMA GfK) <zdenek.sk...@gfk.com>: >> Dear all, >> >> I have a question that is probably pretty stupid, so apologies in advance... >> >> I do a simple >> >>> mydata.tab <- by(my.data.frame, my.data.frame$category, colMeans) >> >> ...works fine, but I need to output the results to some "flat" file (kind of >> table) to work with it in Excel etc. >> >> So I am doing now >> >>> capture.output(data.frame(unlist(mydata.tab)), file="mydata.txt") >> >> ...and process the result in Excel. >> Do you know a more pretty way to do this task? Perhaps something other than >> 'by()' to make a table of colMeans? >> > > Try this: > > do.call("rbind", by(iris[-5], iris[[5]], colMeans)) > >
How about aggregate(iris[-5], iris[5], mean) ? > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > > ______________________________________________ > 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ 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.