Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/visible_utilities.R

Standardize data by mean or standard deviation, with optional centering.

1 2 | ```
standardize(X, method=c("sd","mean"), mle=TRUE, center=FALSE)
standardise(X, method=c("sd","mean"), mle=TRUE, center=FALSE)
``` |

`X` |
A numeric vector, matrix, or data frame. |

`method` |
a string giving the standardization method to use, either |

`mle` |
logical; if |

`center` |
logical; if |

`standardize`

is an alternative to the base **R** function `scale`

, offering more options. Data on a *(-Inf, Inf)* scale, such as normally distributed data, are generally standardized by dividing by the standard deviation. However, it is often more appropriate to standardize data on a *[0, Inf)* scale, such as Weibull or gamma distributed data, by dividing by the mean.

So far as the numerical values of the data are concerned, `standardize(X, "sd", FALSE, TRUE)`

is equivalent to `scale(X)`

. See the note on attributes in Value, below.

`standardise`

is an alias for `standardize`

.

A vector or matrix of the same dimension as `X`

, with the attribute `standardized`

, which is a list with elements `scale`

and `center`

. These have the same meanings as `scaled:scale`

and `scaled:center`

in the return value attributes of `scale`

. If `center`

is `FALSE`

, then `[email protected]`

will be `NULL`

.

Daniel Dvorkin

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ```
set.seed(123)
X = rmvweisd(5, 1:3, 3:1)
standardize(X, "mean")
# [,1] [,2] [,3]
# [1,] 0.4600131 0.8392135 1.3481948
# [2,] 1.0188317 1.0361609 1.3975700
# [3,] 1.5355348 0.3813876 0.6260400
# [4,] 0.5390977 1.7176610 0.9614062
# [5,] 1.4465227 1.0255769 0.6667891
# attr(,"standardized")
# attr(,"standardized")$scale
# [1] 0.2457062 0.6110324 1.0480777
#
# attr(,"standardized")$center
# NULL
colMeans(standardize(X, "mean"))
# [1] 1 1 1
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.