gscale: Scaling and centering of matrix.

Description Usage Arguments Details Value See Also Examples

View source: R/gscale.R

Description

gscale standardize the values in a matrix. This is a matrix version of scale in the R package base.

Usage

1
gscale(mat, center = TRUE, scale = TRUE, diag = FALSE)

Arguments

mat

a matrix to be transformed.

center

a logical value indicating whether centering should be done. The default value is TRUE.

scale

a logical value indicating whether scaling should be done. The default value is TRUE.

diag

Whether the diagonal value is considered or not. The defalt value is FALSE(not considered). With this defalut setting, the diagonal values are set to be NA.

Details

This function first vectrizes the values in a matrix and then passes to the scale function in R package base. The returned values are then converted into the original matrix format. If center is TRUE, then centering is done by subtracting the means (omitting NAs) of the matrix from the original values in the matrix. If scale is TRUE, then scaling is done by dividing the (centered) values in the matrix by their standard deviations if center is TRUE, and the root mean square otherwise. If scale is FALSE, no scaling is done. If diag is TURE, the diagonal values are included for the transformation.

Value

a scaled matrix defined by the scaling method.

See Also

scale

Examples

1
2
3
4
5
6
7
8
9
mat <- matrix(c(1,2,3,
               4,5,6,
               7,8,9),3,3,byrow = TRUE)
dimnames(mat) <- list(1:3, c("A","B","C"))

gscale(mat)
gscale(mat, diag = TRUE)
gscale(mat, center = TRUE, scale = FALSE, diag = TRUE)
gscale(mat, center = FALSE, scale = TRUE, diag = TRUE)

huhn1234/vogeltools documentation built on Jan. 17, 2020, 5:21 p.m.