center_scale | R Documentation |
Center and scale a set of variables. Other columns are passed through.
center_scale(d, center, scale)
d |
data.frame to work with |
center |
named vector of variables to center |
scale |
named vector of variables to scale |
d with centered and scaled columns altered
d <- data.frame(x = 1:5,
y = c('a', 'a', 'b', 'b', 'b'))
vars_to_transform = "x"
t <- base::scale(as.matrix(d[, vars_to_transform, drop = FALSE]),
center = TRUE, scale = TRUE)
t
centering <- attr(t, "scaled:center")
scaling <- attr(t, "scaled:scale")
center_scale(d, center = centering, scale = scaling)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.