Skip to content

Single factor from interaction.

2 messages · Rolf Turner, Chuck Cleland

#
I have a vague recollection of seeing reference, fairly recently, to
a function that forms a single factor which ``codes'' the interaction
between two (or more?) factors.  Do I recollect correctly?  It would
be easy enough to roll one's own, but if there is an existing
function it probably does a much cleverer job than I would do.

				cheers,

					Rolf Turner
					rolf at math.unb.ca
#
Are you looking for interaction() ?

a <- gl(2, 4, 8)
b <- gl(2, 2, 8, label = c("ctrl", "treat"))
s <- gl(2, 1, 8, label = c("M", "F"))

interaction(a, b)
[1] 1.ctrl  1.ctrl  1.treat 1.treat 2.ctrl  2.ctrl  2.treat 2.treat
Levels: 1.ctrl 2.ctrl 1.treat 2.treat

interaction(a, b, s, sep = ":")
[1] 1:ctrl:M  1:ctrl:F  1:treat:M 1:treat:F 2:ctrl:M  2:ctrl:F 
2:treat:M 2:treat:F

Levels: 1:ctrl:M 2:ctrl:M 1:treat:M 2:treat:M 1:ctrl:F 2:ctrl:F 
1:treat:F 2:treat:F
Rolf Turner wrote: