### example:start v <- sample(rnorm(200), 100, replace=T) k <- rep.int(c("locA", "locB", "locC", "locD"), 25) tapply(v, k, summary) ### example:end ... (hopefully) produces 4 summaries of v according to k group membership. How can I transform the output into a nice table with the croups as columns and the interesting statistics as lines? Thx, S?ren
soeren.vogel at eawag.ch wrote:> ### example:start > v <- sample(rnorm(200), 100, replace=T) > k <- rep.int(c("locA", "locB", "locC", "locD"), 25) > tapply(v, k, summary) > ### example:endMaybe this could be a solution: t1 <- tapply(v, k, summary) t2 <- sapply(t1, cbind) rownames(t2) <- names(t1[[1]]) t2 Ciao, domenico> > ... (hopefully) produces 4 summaries of v according to k group > membership. How can I transform the output into a nice table with the > croups as columns and the interesting statistics as lines? > > Thx, S?ren > > ______________________________________________ > R-help at 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. >
Dear Sören, How about this? do.call(cbind,tapply(v, k, summary)) HTH, Jorge On Fri, Mar 6, 2009 at 10:48 AM, <soeren.vogel@eawag.ch> wrote:> ### example:start > v <- sample(rnorm(200), 100, replace=T) > k <- rep.int(c("locA", "locB", "locC", "locD"), 25) > tapply(v, k, summary) > ### example:end > > ... (hopefully) produces 4 summaries of v according to k group membership. > How can I transform the output into a nice table with the croups as columns > and the interesting statistics as lines? > > Thx, Sören > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
soeren.vogel at eawag.ch wrote:> ### example:start > v <- sample(rnorm(200), 100, replace=T) > k <- rep.int(c("locA", "locB", "locC", "locD"), 25) > tapply(v, k, summary) > ### example:endThis one is better: do.call(cbind, tapply(v,k,summary)) Ciao, domenico> > ... (hopefully) produces 4 summaries of v according to k group > membership. How can I transform the output into a nice table with the > croups as columns and the interesting statistics as lines? > > Thx, S?ren > > ______________________________________________ > R-help at 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. >
On 06.03.2009, at 16:48, soeren.vogel at eawag.ch wrote:> ### example:start > v <- sample(rnorm(200), 100, replace=T) > k <- rep.int(c("locA", "locB", "locC", "locD"), 25) > tapply(v, k, summary) > ### example:end > > ... (hopefully) produces 4 summaries of v according to k group > membership. How can I transform the output into a nice table with > the croups as columns and the interesting statistics as lines?### Right??? and good??? solution: sapply(by(v, list(area=k), function(x)x, simplify=F), summary) S?ren (again)