sumStats: Compute Summary Statistics

View source: R/sumStats.R

sumStatsR Documentation

Compute Summary Statistics

Description

Creates a dataset of specified summary statistics from a collection of data.

Usage

sumStats(..., group = NULL, Num = "Num", Stats = list(Mean = mean, StdDev
  = sd), Probs = (0:4)/4, na.rm = TRUE)

Arguments

group

list whose components are interpreted as categories, each of the same length as the objects in ... The e lements of the categories define the position in a multi-way array corresponding to each observation. Missing values (NAs) are allowed. The names of group are used as the names of the columns in the output dataset. If a vector is given, it will be treated as a list with one component. The default is NULL, which indicates no grouping variable.

Num

a character string indicating the name of the column that contains the number of nonmissing observations.

Stats

a tagged list. An element in the list should have the name of the target variable in the output data set, a nd it should be a function that accepts the na.rm argument and computes a single value. See Notes for commonly used functions. The default is the target columns Mean and StdDev, which are computing using functions mean and stdev.

Probs

vector of desired probability levels. Values must be between 0 and 1. Minimum returned for probs=0 and maximum returned for probs=1. Default is c(0.0, 0.25, 0.50, 0.75, 1.0).

na.rm

logical; if TRUE, then missing values are removed from each column in ... before computing the statistics

...

any number of arguments, which can be of many different forms: a dataset, selected columns of a dataset, vectors, and matrices. If a dataset is supplied, then nonnumeric columns are removed before computing statistics.

Value

A data frame containing columns identifying each variable in ..., any grouping variables, and the requested statistics as named in the call.

Note

Commonly used functions referenced in the Stats arguments include mean, sd, skew and var.

The statistics requested by the Probs argument are computed by the quantile function using type=2.

References

Helsel, D.R. and Hirsch, R.M., 2002, Statistical methods in water resources: U.S. Geological Survey Techniques of Water-Resources Investigations, book 4, chap. A3, 522 p.

See Also

mean, sd, skew, var, quantile,

Examples

## Generate a random sample
set.seed(222)
XX.rn <- rexp(32)
sumStats(XX.rn)

USGS-R/smwrStats documentation built on Oct. 11, 2022, 6:15 a.m.