trans: Transform data

dat_transR Documentation

Transform data

Description

Perform data set transformation

Usage

dat_trans(x, method = "auto", na.rm = TRUE, add = 1)

vec_trans(x, method = "auto", na.rm = TRUE, add = 1)

Arguments

x

a matrix, data frame or vector.

method

transformation method, including: "center", "auto", "range", "pareto", "vast", "level", "log", "log10", "sqrt" and "asinh".

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

add

a shift value for log transformation.

Value

transformed data

References

Berg, R., Hoefsloot, H., Westerhuis, J., Smilde, A. and Werf, M. (2006), Centering, scaling, and transformations: improving the biological information content of metabolomics data, BMC Genomics, 7:142

Examples

 data(iris)

 ## transform an vector
 vec <- iris[, 1]
 dat_trans(vec, method = "auto")
 vec_trans(vec, method = "auto")

 ## transform a data frame
 mat <- iris[, 1:4]
 dat_trans(mat, method = "log")

 ## transform data frame under different conditions
 plyr::ddply(iris, ("Species"), function(x, method) {
   dat_trans(x[, 1:4], method = method)
 }, method = "range")

## use 'tidyverse'
library(dplyr)
library(tidyr)
library(purrr)

## transform whole data set
iris %>% mutate(across(where(is.numeric), ~ vec_trans(., method = "range")))

## transform data set within groups
iris %>% 
  group_by(Species) %>%
  mutate(across(where(is.numeric), ~ vec_trans(., method = "range")))

wanchanglin/mtExtra documentation built on Aug. 2, 2024, 5:47 p.m.