fct_ord: Factor ordering functions

Description Usage Arguments Value

Description

Factor ordering functions

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
fct_ord_alphabet(x, ..., rev_lvl = FALSE)

fct_ord_natural(x, ...)

fct_ord_by(x, by, ..., .agg = base::mean, .args_agg = list(),
  .sort = base::sort, .args_sort = list(), rev_lvl = FALSE)

fct_ord_clust(x, data, ..., .dist = stats::dist, .args_dist = list(),
  .clust = stats::hclust, .args_clust = list(), .lvl = function(x)
  x$labels[x$order], rev_lvl = FALSE, return_clust = FALSE)

Arguments

x

vector: object to be ordered. Can already be a factor

...

arguments to pass to 'factor'

rev_lvl

logical: whether the factor order should be ordered descending. IE reverse factor levels.

by

vector: metric to determine factor order

.agg, .sort

function: function to aggregate and sort values. 'by' is grouped by 'x' and aggregated by '.agg'. The end result is a named vector, where each name is a factor level and each value is the aggregated 'by'. The factor levels can then be sorted into their new order by '.sort'. '.agg' should be a one-argument function that returns a single value. '.sort' should take and return a named vector of equal length. The order of the names of the output of '.sort' determines the final factor levels.

.args_agg, .args_sort

list: arguments passed to '.agg' and '.sort'

data

dist-able object: data to be passed to '.dist'. The names of the object should correspond to the factor levels of the factor that needs to be ordered.

.dist, .clust, .lvl

function: functions to calculate a distance object from 'data', cluster based on that distance object, and extract factor levels from that cluster object. '.dist' should take 'data' as its first arguments and return a distance object. The default 'dist' calculates distances between the rows of a matrix.'.clust' should take that distance object as its first argument and return a cluster object. The default 'hclust' performs hierarchical clustering. '.lvl' should take that cluster object and extract a character string to use as factor levels.

.args_clust, .args_dist

list: arguments to pass to '.clust' and '.dist'

return_clust

logical: should the cluster object be returned with the factor? If so, a list is returned with the factor in the first position and the cluster object in the second.

Value

factor: factor ordered accoring to functions. Possibly with cluster object.


biodatacore/biodatacoreUtils documentation built on May 28, 2019, 7:11 p.m.