colDevs: Calculate column deviations from central values

View source: R/colDevs.R

colDevsR Documentation

Calculate column deviations from central values

Description

colDevs calculates the column deviations of data values from a central value (mean, median, etc.), possibly stratified by a grouping variable.

Usage

colDevs(x, group, center = mean, ...)

Arguments

x

A numeric data frame or matrix.

group

A factor (or variable that can be coerced to a factor) indicating the membership of each observation in x in one or more groups. If missing, all the data is treated as a single group.

center

A function used to center the values (for each group if group is specified. The function must take a vector argument and return a scalar result.

...

Arguments passed down

Details

Conceptually, the function is similar to a column-wise sweep, by group, allowing an arbitrary center function.

Non-numeric columns of x are removed, with a warning.

Value

A numeric matrix containing the deviations from the centering function.

Author(s)

Michael Friendly

See Also

colMeans for column means,

sweep

Examples


data(iris)

Species <- iris$Species
irisdev <- colDevs(iris[,1:4], Species, mean)
irisdev <- colDevs(iris[,1:4], Species, median)
# trimmed mean, using an anonymous function
irisdev <- colDevs(iris[,1:4], Species, function(x) mean(x, trim=0.25))

# no grouping variable: deviations from column grand means
# include all variables (but suppress warning for this doc)
irisdev <- suppressWarnings( colDevs(iris) )


friendly/heplots documentation built on March 8, 2024, 3:39 p.m.