Skip to contents

This function combines vars in vars (from left to right) possibly scaling each variable individually prior to combining

Usage

scale_and_combine(df, vars, name, scale = TRUE)

Arguments

df

data.frame containing vars

vars

Vector of variable names to be combined into one

name

Name of the new variable to be added to df

scale

(logical) Whether to scale each variable prior to combining

Value

df with variable name added

Examples

df <- df |> scale_and_combine(c("x1", "x2", "x3"), name="x", scale=TRUE)
#> [1] "Added var x"