centredAndScaled: Centre and Scale Numeric Data

View source: R/loopFuns.R

centredAndScaledR Documentation

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)

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.

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.

Examples

# 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)


loopevd documentation built on June 23, 2025, 5:09 p.m.