standcol: Standardise the columns of a matrix

Description Usage Arguments Value Author(s) Examples

Description

Enables the centering and scaling of the columns of a matrix, to have zero mean and unit variance.

Usage

1
standcol(x, centre = FALSE, stand = TRUE)

Arguments

x

Matrix to be centred and/or scaled.

centre

Should the columns of x be centred to have zero mean? (TRUE/FALSE)

stand

Should the columns of x be scaled to have unit variance? (TRUE/FALSE)

Value

Returns matrix x with the columns centred and/or scaled.

Author(s)

Theo Pepler

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, centre = FALSE, stand = TRUE)
{
    if (centre) {
        for (i in 1:ncol(x)) {
            x[, i] <- x[, i] - mean(x[, i])
        }
    }
    if (stand) {
        for (i in 1:ncol(x)) {
            x[, i] <- x[, i]/sd(x[, i])
        }
    }
    return(x)
  }

tpepler/theolib documentation built on Aug. 10, 2021, 9:53 a.m.