interaction
computes a factor which represents the interaction
of the given factors. The result of interaction
is always unordered.
interaction(..., drop = FALSE, sep = ".", lex.order = FALSE)
drop
is TRUE
, unused factor levels
are dropped from the result. The default is to retain all
factor levels.sep
which is .
by default.By default, when lex.order = FALSE
, the levels are ordered so
the level of the first factor varies fastest, then the second and so
on. This is the reverse of lexicographic ordering (which you can get
by lex.order = TRUE
), and differs from
:
. (It is done this way for compatibility with S.)
factor
;
:
where f:g
is similar to
interaction(f, g, sep = ":")
when f
and g
are factors.
a <- gl(2, 4, 8)
b <- gl(2, 2, 8, labels = c("ctrl", "treat"))
s <- gl(2, 1, 8, labels = c("M", "F"))
interaction(a, b)
interaction(a, b, s, sep = ":")
stopifnot(identical(a:s,
interaction(a, s, sep = ":", lex.order = TRUE)),
identical(a:s:b,
interaction(a, s, b, sep = ":", lex.order = TRUE)))
Run the code above in your browser using DataLab