[R] multiple tapply

Gabor Grothendieck ggrothendieck at gmail.com
Thu Aug 7 15:39:55 CEST 2008


Here are three ways:

# 1
aggregate(iris[-5], iris[5], mean)

# 2
library(doBy)
summaryBy(.~Species, iris, keep = TRUE)

# 3
library(sqldf)
sqldf("select Species,
   avg(Sepal_Length) Sepal_Length,
   avg(Sepal_Width) Sepal_Width,
   avg(Petal_Length) Petal_Length,
   avg(Petal_Width) Petal_Width
from iris
group by Species")


On Thu, Aug 7, 2008 at 7:01 AM, glaporta <glaporta at freeweb.org> 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
> --
> View this message in context: http://www.nabble.com/multiple-tapply-tp18868063p18868063.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list