interaction
Compute the Interaction of Several Factors

Description

Computes the interaction of several factors and returns a new factor with levels that represent all combinations of the factors supplied as arguments.

Usage

interaction(..., drop = FALSE, sep = ".", lex.order = FALSE)
factorA:factorB

Arguments

... the arguments to interaction can be either a data frame containing all the factors to be used orall the individual factors. It will not understand a combination of factors and data.frames as arguments; you have to pick one form or the other.
factorA a factor.
factorB a factor.
drop if TRUE the levels of the new factor not represented in the data are dropped.
sep a character string. The levels of the output factor are constructed from the levels of the input factors pasted together with sep between them.
lex.order a logical value which determines the ordering of the levels of the output factor. If FALSE, the default, the levels of the first factor are incremented first, then the second, etc. If TRUE, the levels are in lexicographical order: the levels of the last factor are incremented first, then the next to the last, etc.
Value
interaction returns a new factor, whose levels are all possible combinations of the factors supplied as arguments. If drop = TRUE, only the levels represented in the new factor are retained.
If x and y are both factors then x:y returns the same as interaction(x, y, sep=":", lex.order=TRUE).
Examples
with(Sdatasets::catalyst, interaction(Conc, Temp))
interaction(LETTERS[c(1,2,3,3)], factor(letters[c(1,2,2,3)], levels=letters[4:1]))
interaction(LETTERS[c(1,2,3,3)], factor(letters[c(1,2,2,3)], levels=letters[4:1]), drop=TRUE)
interaction(LETTERS[c(1,2,3,3)], factor(letters[c(1,2,2,3)], levels=letters[4:1]), lex.order=TRUE)
factor(c("A","A","B")):factor(c("Two","One","Two"))
Package base version 6.1.1-7
Package Index