[R] multiple tapply
Chuck Cleland
ccleland at optonline.net
Thu Aug 7 14:08:58 CEST 2008
On 8/7/2008 7:01 AM, glaporta wrote:
> Hi folk,
> I tried this and it works just perfectly
> tapply(iris[,1],iris[5],mean)
> but, how to obtain a single table from multiple variables?
> In tapply x is an atomic object so this code doesn't work
> tapply(iris[,1:4],iris[5],mean)
>
> Thanx and great summer holidays
> Gianandrea
And a third approach:
> sapply(split(iris[,1:4], iris$Species), colMeans)
setosa versicolor virginica
Sepal.Length 5.006 5.936 6.588
Sepal.Width 3.428 2.770 2.974
Petal.Length 1.462 4.260 5.552
Petal.Width 0.246 1.326 2.026
--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list