Learn R Programming

loopevd (version 1.0.2)

centredAndScaled: Centre and Scale Numeric Data

Description

centredAndScaled centres (subtracts the mean) and scales (divides by the standard deviation) each column of a numeric vector or matrix.

Usage

centredAndScaled(nsloc = NULL)

Value

A numeric vector or matrix of the same dimensions as the input, with each column centred to mean zero and scaled to unit variance. If nsloc is NULL, returns NULL.

Arguments

nsloc

data.frame. If NULL or of length zero, the function returns nsloc unchanged.

Details

If nsloc has only one column, the function computes the mean and standard deviation of the entire vector. If nsloc has multiple columns, each column is centred and scaled independently.

Examples

Run this code
# Centre and scale a simple vector
centredAndScaled(data.frame(1:10))

# Centre and scale each column of a matrix
mat <- as.data.frame(matrix(stats::rnorm(30), nrow = 10, ncol = 3))
centredAndScaled(mat)

Run the code above in your browser using DataLab