weave_factors | R Documentation |
Computes a new factor out of combinations of input factors.
weave_factors(..., drop = TRUE, sep = ".", replaceNA = TRUE)
... |
The vectors |
drop |
A |
sep |
A |
replaceNA |
A |
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.
A factor
representing combinations of input factors.
interaction()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.