center_scale {vtreat} | R Documentation |
Center and scale a set of variables.
Description
Center and scale a set of variables. Other columns are passed through.
Usage
center_scale(d, center, scale)
Arguments
d |
data.frame to work with |
center |
named vector of variables to center |
scale |
named vector of variables to scale |
Value
d with centered and scaled columns altered
Examples
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)
[Package vtreat version 1.6.5 Index]