View source: R/Module_transformDF.R
transformVar | R Documentation |
transform a numeric vector
transformVar(x, type, logfirst = FALSE, warning.print = FALSE)
x |
is a numeric vector |
type |
"none", "standardize" (rescale to 0-1), or "normalize" (rescale to mean=0, sd =1) |
logfirst |
if TRUE, do a log-transform BEFORE applying either standardize or normalize |
warning.print |
if TRUE print a warning if Perry et al 2021 0 fix is triggered |
Typically called from within transformDF
. If any zeroes in the data,
then the log-transform causes problems.
Using the strategy from Perry et al 2021
(https://journals.plos.org/plosone/article/comments?id=10.1371/journal.pone.0245941)
which replaces 0 with a random value greater than 0 and less than one-half of the
lowest non-zero value in the data for that variable. If the data has negative values, a
constant equal to min(x)* 1.01 is added to all values (i.e. smallest value is a
bit larger than 0).
A transformed vector
transformVar(X = mtcars$mpg, type = "standardize", logfirst = FALSE) transformVarX = mtcars$mpg, type = "normalize", logfirst = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.