Re: [R] tapply

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Tue, 08 Apr 2008 07:13:18 -0400

On 4/8/2008 5:14 AM, Manuel Montes wrote:
> Does anyone have something like tapply for matrices? I would like to average the contents of columns
> according to factors but tapply works only with one column at each time. Is something available to do
> everything in one step?
> Many thanks.
> Manuel Montes

   How about aggregate()? For example:

aggregate(iris[,c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")], by = list(Species = iris$Species), FUN = mean)

      Species Sepal.Length Sepal.Width Petal.Length Petal.Width
1     setosa        5.006       3.428        1.462       0.246
2 versicolor        5.936       2.770        4.260       1.326
3  virginica        6.588       2.974        5.552       2.026


> ______________________________________________
> 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.
-- 
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

______________________________________________
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.
Received on Tue 08 Apr 2008 - 11:22:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Apr 2008 - 11:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive