# find_max: Utility functions for factors and compositional data In mefa4: Multivariate Data Handling with S4 Classes and Sparse Matrices

## Description

Utility functions for factors and compositional data.

## Usage

 ```1 2 3 4 5``` ```compare_sets(x, y) find_max(x) find_min(x) reclass(x, map, all = FALSE, allow_NA = FALSE) redistribute(x, source, target = NULL) ```

## Arguments

 `x, y` any type for `compare_sets`, matrix for `find_max`, `find_min`, and `redistribute`, a factor for `reclass`. `map` a reclassification matrix with 2 columns (1st: original levels, 2nd: output levels mapped to original levels). `all` logical, whether all levels from mapping matrix should be applied on the return object. `allow_NA` logical, whether `NA`s are allowed as part of `map`. `source` numeric or character, single column index for input matrix `x`. `target` numeric or character, column index or indices for input matrix `x`.

## Value

A matrix `compare_sets`.

A data frame for `find_max` and `find_min`.

A reclassified factor for `reclass`.

A matrix for `redistribute` where the source column values are redistributed among the target columns proportionally.

## Author(s)

Peter Solymos <solymos@ualberta.ca>

`intersect`, `setdiff`, `union`, `relevel`, `reorder`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28``` ```## numeric vector compare_sets(1:10, 8:15) ## factor with 'zombie' labels compare_sets(factor(1:10, levels=1:10), factor(8:15, levels=1:15)) (mat <- matrix(rnorm(10*5), 10, 5)) (m <- find_max(mat)) ## column indices as.integer(m\$index) find_min(mat) map <- cbind(c("a","b","c","d","e","f","g"), c("A","B","B","C","D","D","E")) #x <- factor(sample(map[1:6,1], 100, replace=TRUE), levels=map[,1]) x <- as.factor(sample(map[1:6,1], 100, replace=TRUE)) x[2] <- NA table(x, reclass(x, map, all = FALSE), useNA="always") table(x, reclass(x, map, all = TRUE), useNA="always") map[c(4, 7), 2] <- NA table(x, reclass(x, map, all = FALSE, allow_NA = TRUE), useNA="always") table(x, reclass(x, map, all = TRUE, allow_NA = TRUE), useNA="always") (mat2 <- exp(mat) / rowSums(exp(mat))) (rmat2 <- redistribute(mat2, source = 1, target = 2:4)) colMeans(mat2) colMeans(rmat2) stopifnot(abs(sum(mat2) - sum(rmat2)) < 10^-6) ```

mefa4 documentation built on Oct. 7, 2021, 1:06 a.m.