find_max | R Documentation |
Utility functions for factors and compositional data.
compare_sets(x, y) find_max(x) find_min(x) reclass(x, map, all = FALSE, allow_NA = FALSE) redistribute(x, source, target = NULL)
x, y |
any type for |
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 |
source |
numeric or character, single column index for input matrix |
target |
numeric or character, column index or indices for input matrix |
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.
Peter Solymos <solymos@ualberta.ca>
intersect
, setdiff
,
union
, relevel
, reorder
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.