center_scale: Center and scale a set of variables.

View source: R/center_scale.R

center_scaleR 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)


vtreat documentation built on Aug. 20, 2023, 1:08 a.m.