Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

umx_scale

Scale data columns, skipping non-scalable columns


Description

umx_scale applies scale to the columns of a data.frame. By default it scales all numeric columns, and is smart enough to skip non-scalable columns (strings, factors, etc.).

You can also select which columns to convert. This is useful when you want to avoid numeric columns which are actually factors.

note: By default, the attributes which scale adds ("scaled:center" and "scaled:scale" removed to leave nice numeric columns. Set attr= TRUE to preserve these.

Usage

umx_scale(
  df,
  varsToScale = NULL,
  coerce = FALSE,
  attr = FALSE,
  verbose = FALSE
)

Arguments

df

A dataframe to scale (or a numeric vector)

varsToScale

(leave blank to scale all)

coerce

Whether to coerce non-numerics to numeric (Defaults to FALSE.

attr

to strip off the attributes scale creates (FALSE by default)

verbose

Whether to report which columns were scaled (default FALSE)

Value

  • new dataframe with scaled variables

References

See Also

umx_scale_wide_twin_data scale

Examples

data(twinData) 
df = umx_scale(twinData, varsToScale = c("wt1", "wt2"))
df = umx_scale(twinData,  attr= TRUE)
plot(wt1 ~ wt2, data = df)

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.