| robust_scale | R Documentation |
Applies robust scaling to numeric and categorical variables. For numeric variables, the function centers by the median and scales by the MAD. For categorical variables with 2–4 unique levels, it applies a custom transformation to map them to numeric values.
robust_scale(x, group)
x |
A numeric vector, factor, matrix, or data frame. If a matrix or data frame is provided, scaling is applied column-wise. |
group |
vector indicating which group is the TG to scale to |
This function is designed to make numeric and categorical variables comparable. This is an internal function that should not be used by package users.
A scaled numeric vector or a data frame with scaled columns.
dat<-data.frame(x=rnorm(100, 10, 3), sex=factor(rbinom(100, 1, 0.5), labels=c("M","F")))
x<- robust_scale(dat$x, dat$sex)
round(median(x), 2)
round(mad(x), 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.