The get_transform() gets transformation of numeric variable.

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

Arguments

x

numeric. numeric for transform

method

character. transformation method of numeric variable

Value

numeric. transformed numeric vector.

Details

The supported transformation method is follow.:

  • "log" : log transformation. log(x)

  • "log+1" : log transformation. log(x + 1). Used for values that contain 0.

  • "log+a" : log transformation. log(x + 1 - min(x)). 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

Examples

# log+a transform 
get_transform(iris$Sepal.Length, "log+a")
#>   [1] 0.58778666 0.47000363 0.33647224 0.26236426 0.53062825 0.74193734
#>   [7] 0.26236426 0.53062825 0.09531018 0.47000363 0.74193734 0.40546511
#>  [13] 0.40546511 0.00000000 0.91629073 0.87546874 0.74193734 0.58778666
#>  [19] 0.87546874 0.58778666 0.74193734 0.58778666 0.26236426 0.58778666
#>  [25] 0.40546511 0.53062825 0.53062825 0.64185389 0.64185389 0.33647224
#>  [31] 0.40546511 0.74193734 0.64185389 0.78845736 0.47000363 0.53062825
#>  [37] 0.78845736 0.47000363 0.09531018 0.58778666 0.53062825 0.18232156
#>  [43] 0.09531018 0.53062825 0.58778666 0.40546511 0.58778666 0.26236426
#>  [49] 0.69314718 0.53062825 1.30833282 1.13140211 1.28093385 0.78845736
#>  [55] 1.16315081 0.87546874 1.09861229 0.47000363 1.19392247 0.64185389
#>  [61] 0.53062825 0.95551145 0.99325177 1.02961942 0.83290912 1.22377543
#>  [67] 0.83290912 0.91629073 1.06471074 0.83290912 0.95551145 1.02961942
#>  [73] 1.09861229 1.02961942 1.13140211 1.19392247 1.25276297 1.22377543
#>  [79] 0.99325177 0.87546874 0.78845736 0.78845736 0.91629073 0.99325177
#>  [85] 0.74193734 0.99325177 1.22377543 1.09861229 0.83290912 0.78845736
#>  [91] 0.78845736 1.02961942 0.91629073 0.53062825 0.83290912 0.87546874
#>  [97] 0.87546874 1.06471074 0.58778666 0.87546874 1.09861229 0.91629073
#> [103] 1.33500107 1.09861229 1.16315081 1.45861502 0.47000363 1.38629436
#> [109] 1.22377543 1.36097655 1.16315081 1.13140211 1.25276297 0.87546874
#> [115] 0.91629073 1.13140211 1.16315081 1.48160454 1.48160454 0.99325177
#> [121] 1.28093385 0.83290912 1.48160454 1.09861229 1.22377543 1.36097655
#> [127] 1.06471074 1.02961942 1.13140211 1.36097655 1.41098697 1.52605630
#> [133] 1.13140211 1.09861229 1.02961942 1.48160454 1.09861229 1.13140211
#> [139] 0.99325177 1.28093385 1.22377543 1.28093385 0.91629073 1.25276297
#> [145] 1.22377543 1.22377543 1.09861229 1.16315081 1.06471074 0.95551145

if (requireNamespace("forecast", quietly = TRUE)) {
  # Box-Cox transform 
  get_transform(iris$Sepal.Length, "Box-Cox")

  # Yeo-Johnson transform 
  get_transform(iris$Sepal.Length, "Yeo-Johnson")
} else {
  cat("If you want to use this feature, you need to install the forecast package.\n")
}
<<<<<<< HEAD
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo 
=======
>>>>>>> 2455413f029244b566a37aeed1916eea79ac483b
#>   [1] 0.8361065 0.8305486 0.8246007 0.8214675 0.8333738 0.8437919 0.8214675
#>   [8] 0.8333738 0.8148529 0.8305486 0.8437919 0.8276259 0.8276259 0.8113584
#>  [15] 0.8529844 0.8507892 0.8437919 0.8361065 0.8507892 0.8361065 0.8437919
#>  [22] 0.8361065 0.8214675 0.8361065 0.8276259 0.8333738 0.8333738 0.8387509
#>  [29] 0.8387509 0.8246007 0.8276259 0.8437919 0.8387509 0.8461961 0.8305486
#>  [36] 0.8333738 0.8461961 0.8305486 0.8148529 0.8361065 0.8333738 0.8182203
#>  [43] 0.8148529 0.8333738 0.8361065 0.8276259 0.8361065 0.8214675 0.8413114
#>  [50] 0.8333738 0.8750466 0.8649099 0.8734641 0.8461961 0.8667120 0.8507892
#>  [57] 0.8630584 0.8305486 0.8684666 0.8387509 0.8333738 0.8551160 0.8571867
#>  [64] 0.8591991 0.8485275 0.8701757 0.8485275 0.8529844 0.8611556 0.8485275
#>  [71] 0.8551160 0.8591991 0.8630584 0.8591991 0.8649099 0.8684666 0.8718410
#>  [78] 0.8701757 0.8571867 0.8507892 0.8461961 0.8461961 0.8529844 0.8571867
#>  [85] 0.8437919 0.8571867 0.8701757 0.8630584 0.8485275 0.8461961 0.8461961
#>  [92] 0.8591991 0.8529844 0.8333738 0.8485275 0.8507892 0.8507892 0.8611556
#>  [99] 0.8361065 0.8507892 0.8630584 0.8529844 0.8765900 0.8630584 0.8667120
#> [106] 0.8837689 0.8305486 0.8795654 0.8701757 0.8780959 0.8667120 0.8649099
#> [113] 0.8718410 0.8507892 0.8529844 0.8649099 0.8667120 0.8851057 0.8851057
#> [120] 0.8571867 0.8734641 0.8485275 0.8851057 0.8630584 0.8701757 0.8780959
#> [127] 0.8611556 0.8591991 0.8649099 0.8780959 0.8809999 0.8876891 0.8649099
#> [134] 0.8630584 0.8591991 0.8851057 0.8630584 0.8649099 0.8571867 0.8734641
#> [141] 0.8701757 0.8734641 0.8529844 0.8718410 0.8701757 0.8701757 0.8630584
#> [148] 0.8667120 0.8611556 0.8551160