vtreat (version 1.6.2)

center_scale: 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

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab