
上QQ阅读APP看书,第一时间看更新
There's more...
If you need to compute an aggregated summary of statistics against data in different groups, you can use the aggregate and reshape functions to compute the summary statistics of data subsets:
- Use aggregate to calculate the mean of each iris attribute group by the species:
> aggregate(x=iris[,1:4],by=list(iris$Species),FUN=mean)
- Use reshape to calculate the mean of each iris attribute group by the species:
> library(reshape) > iris.melt <- melt(iris,id='Species') > cast(Species~variable,data=iris.melt,mean, subset=Species %in% c('setosa','versicolor'), margins='grand_row')
For information on reshape and aggregate, refer to the help documents by using ?reshape or ?aggregate.