[R] getting a new factor

Richard M. Heiberger rmh at temple.edu
Sun Dec 31 00:47:05 CET 2006


> tmp <- data.frame(G=factor(letters[c(1,2,3,1,2,3)]), 
+                   S=factor(LETTERS[c(1,1,1,2,2,2)]))
> tmp
  G S
1 a A
2 b A
3 c A
4 a B
5 b B
6 c B
> tmp$G.S <- with(tmp, interaction(G, S))
> tmp
  G S G.S
1 a A a.A
2 b A b.A
3 c A c.A
4 a B a.B
5 b B b.B
6 c B c.B
>



More information about the R-help mailing list