transform | R Documentation |
Performs variable transformation for standardization and resolving skewness of numerical variables.
transform(
x,
method = c("zscore", "minmax", "log", "log+1", "sqrt", "1/x", "x^2", "x^3", "Box-Cox",
"Yeo-Johnson")
)
x |
numeric vector for transformation. |
method |
method of transformations. |
transform() creates an transform class. The 'transform' class includes original data, transformed data, and method of transformation.
See vignette("transformation") for an introduction to these concepts.
An object of transform class. Attributes of transform class is as follows.
method : method of transformation data.
Standardization
"zscore" : z-score transformation. (x - mu) / sigma
"minmax" : minmax transformation. (x - min) / (max - min)
Resolving Skewness
"log" : log transformation. log(x)
"log+1" : log transformation. log(x + 1). Used for values that contain 0.
"sqrt" : square root transformation.
"1/x" : 1 / x transformation
"x^2" : x square transformation
"x^3" : x^3 square transformation
"Box-Cox" : Box-Box transformation
"Yeo-Johnson" : Yeo-Johnson transformation
summary.transform
, plot.transform
.
# Standardization ------------------------------
creatinine_minmax <- transform(heartfailure$creatinine, method = "minmax")
creatinine_minmax
summary(creatinine_minmax)
plot(creatinine_minmax)
# Resolving Skewness --------------------------
creatinine_log <- transform(heartfailure$creatinine, method = "log")
creatinine_log
summary(creatinine_log)
plot(creatinine_log)
plot(creatinine_log, typographic = FALSE)
# Using dplyr ----------------------------------
library(dplyr)
heartfailure %>%
mutate(creatinine_log = transform(creatinine, method = "log+1")) %>%
lm(sodium ~ creatinine_log, data = .)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.