Compute Summary Statistics by Group

DESCRIPTION:

A collection of generic functions used to quickly compute summary statistics by groups. The groups are specified by an integer vector having the same length as the data vector.

USAGE:

igroupAlls(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupAnys(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupMaxs(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupMeans(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupMins(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupProds(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupRanges(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)
igroupSums(x, group=NULL, na.rm=F, weights=NULL, ngroups=<<see below>>)

REQUIRED ARGUMENTS:

x
a vector of data.

OPTIONAL ARGUMENTS:

group
an integer vector having the same length as x and values in the range 1:ngroups where ngroups<=length(x). The default value is NULL, meaning that the entire vector x is one group.
na.rm
a logical flag indicating whether missing values should be removed before computation. The default value is FALSE.
weights
a numeric vector having the same length as x containing weights to use in the summary calculations.
ngroups
an integer specifying the number of groups. The summary is calculated for groups 1:ngroups. The default value is max(groups) or 1 if groups is missing or NULL.

VALUE:

a vector of length ngroups for all summaries except the Range summary, a matrix having 2 rows and ngroups columns. The ith element (or column for Range) contains the summary value for x[group == i].

DETAILS:

This collection of functions, igroupXXXs, calculates summary statistics for groups of data in the input vector, x . The summary functions perform these computations:

    All - all of the elements in a group are TRUE.
    Any - any of the elements in a group are TRUE.
    Max - maximum of all the elements in a group.
    Min - minimum of all the elements in a group.
    Range - minimum and maximum of all elements in a group.
    Mean - mean value of all the elements in a group.
    Sum - sum of all elements in a group.
    Prod - product of all elements in a group.

NOTE:

NA's and out-of-range elements in groups cause the corresponding element in x to not be included in the summary calculations.

SEE ALSO:

, , , , , , , .

EXAMPLES:

# compute ranges for Plant groups in CO2 update values
igroupRanges(CO2$uptake, group=CO2$Plant)