A function which performs row-, column-, double- or overall-centering of a matrix

centering(Mat, rowcenter = FALSE, colcenter = FALSE, grandcenter = FALSE)

Arguments

Mat

A numerical matrix.

rowcenter

Logical. If TRUE the matrix is row-centered

colcenter

Logical. If TRUE the matrix is columns centered

grandcenter

Logical. If TRUE the matrix is only centered by a subtraction by the overall (grand) mean of all matrix elements. Only applies if both rowcenter and colcenter are FALSE.

Value

A centered matrix

Details

If both row- and colcenter are TRUE the matrix is double centered. This is done by first subtracting the pre-computed row-means, then the pre-computed column means and finally, the grand mean is added back in.

Examples

data(BCdata) Xc <- centering(BCdata$X, FALSE, TRUE, FALSE)