Learn R Programming

doBy (version 0.1)

summaryBy: Function to calculate groupwise summary statistics

Description

Function to calculate groupwise summary statistics, much like the summary procedure of SAS

Usage

summaryBy(formula, data = parent.frame(), id = NULL, FUN = mean,...)

Arguments

formula
A formula object, see examples below
data
A data frame
id
A formula specifying variables which data are not grouped by but which should appear in the output. See examples below.
FUN
A list of functions to be applied, see examples below.
...
Additional arguments to FUN.

Value

  • A data frame

Details

NAs are removed before calculating summary statistics

See Also

orderBy, splitBy, doby.xtabs,

Examples

Run this code
data(dietox)
dietox12    <- subset(dietox,dietox$Time==12)summaryBy(Weight+Feed~Evit+Cu,      data=dietox12, FUN=c(mean,var), na.rm=TRUE)  

summaryBy(Weight+Feed~Evit+Cu+Time, data=subset(dietox,Time>1),
FUN=c(mean,var), na.rm=TRUE)  

summaryBy(Weight+Feed~Evit+Cu,      data=dietox12, FUN=length)  

summaryBy(log(Weight)+Feed~Evit+Cu,      data=dietox12)  
summaryBy(.~Evit+Cu,      data=dietox12, id=~Litter, FUN=mean)

data(warpbreaks)
summaryBy(breaks ~ wool+tension, warpbreaks)
summaryBy(breaks ~., warpbreaks)
summaryBy(.~ wool+tension, warpbreaks)

summaryBy(Ozone~Month, data=airquality,FUN=c(mean,var),na.rm=TRUE)

Run the code above in your browser using DataLab