weave_factors {ggh4x} | R Documentation |
Bind together factors
Description
Computes a new factor out of combinations of input factors.
Usage
weave_factors(..., drop = TRUE, sep = ".", replaceNA = TRUE)
Arguments
... |
The vectors |
drop |
A |
sep |
A |
replaceNA |
A |
Details
weave_factors()
broadly resembles interaction(..., lex.order = TRUE)
, with a slightly altered approach to non-factor inputs.
In other words, this function orders the new levels such that the levels of
the first input variable in ...
is given priority over the second
input, the second input has priority over the third, etc.
This function treats non-factor inputs as if their levels were
unique(as.character(x))
, wherein x
represents an input.
Value
A factor
representing combinations of input factors.
See Also
Examples
f1 <- c("banana", "apple", "apple", "kiwi")
f2 <- factor(c(1, 1:3), labels = c("house", "cat", "dog"))
# Notice the difference in level ordering between the following:
interaction(f1, f2, drop = TRUE, lex.order = TRUE)
interaction(f1, f2, drop = TRUE, lex.order = FALSE)
weave_factors(f1, f2)
# The difference is in how characters are interpreted
# The following are equivalent
interaction(f1, f2, drop = TRUE, lex.order = TRUE)
weave_factors(as.factor(f1), f2)