center: Data Centering

View source: R/center.R

centerR Documentation

Data Centering

Description

Function to perform mean-centering or median-centering on a numeric matrix or data frame.

Usage

center(x, method = "mean", drop_na = FALSE, drop.na = deprecated())

Arguments

x

A numeric matrix or data frame.

method

A character string specifying the centering method, either "mean" or "median".

drop_na

A logical value indicating whether to ignore missing values (NA) when computing the column means or medians. Missing values are kept in the output.

drop.na

[Deprecated] Use drop_na.

Details

Mean-centering calculates the mean of each column and subtracts this from the column. Median-centering is very similar to mean-centering except that the reference point is the median of each column rather than the mean.

Value

A numeric matrix with the same dimensions as the input, with columns centered according to the specified method. The column centers are stored in the "center" attribute.

Author(s)

Christian L. Goueguel

Examples

data(forageLIBS)
spectra <- forageLIBS[-(1:14)]  # the spectral channels
center(spectra)[1:3, 1:4]
center(spectra, method = "median")[1:3, 1:4]

specProc documentation built on Nov. 20, 2026, 5:11 p.m.