[R] Summary grouped by factor

soeren.vogel at eawag.ch soeren.vogel at eawag.ch
Fri Mar 6 17:29:31 CET 2009


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)




More information about the R-help mailing list