transform: Data Transformations

View source: R/transform.R

transformR Documentation

Data Transformations

Description

Performs variable transformation for standardization and resolving skewness of numerical variables.

Usage

transform(
  x,
  method = c("zscore", "minmax", "log", "log+1", "sqrt", "1/x", "x^2", "x^3", "Box-Cox",
    "Yeo-Johnson")
)

Arguments

x

numeric vector for transformation.

method

method of transformations.

Details

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.

Value

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

See Also

summary.transform, plot.transform.

Examples


# 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 = .)

   

dlookr documentation built on May 29, 2024, 2 a.m.