Section 38 Data Analysis: Summary Statistics by Group

  • Read the help file for the different functions to create summary statistics of the data.

  • Calculate mean of Age grouped by Sex

  • Calculate mean of Wt grouped by Sex

  • Calculate mean of Age grouped by Sex and Vac

  • Calculate mean of Wt grouped by Sex and Vac

  • Calculate mean of Age > 1.2 grouped by Sex

  • Calculate mean of Age > 1.2 grouped by Sex and Vac



##aggregate

aggregate(x=DF$Age, by=list(DF$Sex), FUN=mean, na.rm=TRUE)
aggregate(x=Age, by=list(Sex), data=DF, FUN=mean, na.rm=TRUE)
aggregate(Age ~ Sex, data=DF, FUN=mean, na.rm=TRUE)

aggregate(x=Age, by=list(Sex, Vac), data=DF, FUN=mean, na.rm=TRUE)
aggregate(Age ~ Sex + Vac, data=DF, FUN=mean, na.rm=TRUE)

aggregate(Age ~ Sex + Vac, data=DF[DF$Age>1.2,], FUN=mean, na.rm=TRUE)