transformer: Transforming Tidy Data

Description Usage Arguments Details Value See Also Examples

Description

This function transforms a table by rows or by columns.

Usage

1
2
3
transformer(.data, func, by = "column", ids = NULL,
  header_name = NULL, preserved_categories = TRUE,
  separated_categories = NULL, ...)

Arguments

.data

A matrix/data_frame/tibble for transforming.

func

A function, which can be anonymous, that will be used to transform the data. (e.g. proportions: x/sum(x)).

by

This denotes how the data should be transformed (column/row). Default: 'column'

ids

The column to transpose by if by = 'row'. Default: The first column.

header_name

A name for the numeric data that will be transposed if by = 'row'.

preserved_categories

A logical denoting weather categorical data should be conserved if by = 'row'. A value of FALSE will cause all categorical data except the ids to be dropped. A value of TRUE will cause the categorical data to preserved by tidyr::uniteing these columns. Default: TRUE

separated_categories

A vector containing ordered column names to use in a previously transposed and categorically preserved table if by = 'row'. Retransposing with this set should yield an exact replicate of the original data. Default: NULL

...

Additional arguments passed on to func.

Details

This function transforms the supplied data using the func parameter, which is used in the purrr package. The purr package allows the use of anonymous functions as described in the link below:

https://jennybc.github.io/purrr-tutorial/ls03_map-function-syntax.html#anonymous_function,_formula

Value

A tibble that has been transformed.

See Also

transposer select_all, select modify

Other Data Manipulators: convert_proportions, metacoder_comp_func_1, transposer, vlookup

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
if(interactive()){
# This example uses data that are no longer available in the MicrobiomeR package,
# however, they can be easily generated with \code{\link{MicrobiomeR}{as_basic_format}}.
 library(MicrobiomeR)
 basic_silva <- as_MicrobiomeR_format(MicrobiomeR::raw_silva_2, "basic_format")
 data <- basic_silva$data$taxa_abundance
 # Get proportions using the anonymous functions
 tax_props <- data %>% transformer(~./sum(.))
 # Get proportions using explicit functions
 alt_tax_props <- data %>% transformer(function(x)x/sum(x))
 }

## End(Not run)

vallenderlab/MicrobiomeR documentation built on Aug. 30, 2019, 11:24 p.m.