[R] Single factor from interaction.

Chuck Cleland ccleland at optonline.net
Thu May 26 14:41:26 CEST 2005


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:
> 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list