Learn R Programming

rmngb (version 0.6-1)

Vars: Form Row and Column Variances

Description

Form row and column variances for numeric arrays.

Usage

colVars(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, twopass = TRUE) rowVars(x, na.rm = FALSE, dims = 1, unbiased = TRUE, SumSquares = FALSE, twopass = TRUE)

Arguments

x
an array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame.
na.rm
logical. Should missing values (including NaN) be omitted from the calculations?
dims
integer: Which dimensions are regarded as ?rows? or ?columns? to sum over. For row*, the sum or mean is over dimensions dims+1, ...; for col* it is over dimensions 1:dims.
unbiased
logical. Should the estimator of the variance be unbiaised, using `(N - 1)` as a denominator?
SumSquares
logical. Should the function return only the sum of squares?
twopass
logical. `twopass = TRUE` is needed for numerical accuracy if mu >> sigma.

Value

A numeric or complex array of suitable size, or a vector if the result is one-dimensional. For the first four functions the dimnames (or `names` for a vector result) are taken from the original array.

Details

These functions are equivalent to use of apply with `FUN = var` with appropriate margins, but are a lot faster.

References

From David Brahm on R-Help, inspired from Package "colSums".

See Also

colSums, apply.

Examples

Run this code
x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
rowVars(x); colVars(x)
# more examples should be included for the other arguments

Run the code above in your browser using DataLab