[R] An index of all possible combinations of variables in a data fram e

Gabor Grothendieck ggrothendieck at myway.com
Tue Sep 28 07:13:11 CEST 2004


Alan Simpson <alan.simpson <at> robertsresearch.com.au> writes:

: Does anybody know of any way to create an index of all the possible
: combinations of variables (factors) in a data frame? ie for 3 factors A, B &
: C we have 
: 
: A
: B
: C
: AB
: AC
: BC
: ABC
:  
: which equates to columns 1, 2, 3, 1:2, (1,3), 2:3 and 1:3.
: 
: I realise that a function like model.matrix does this, but how to get the
: seqence of the index?
: 

Is this what you are looking for?

R> attributes(terms(~ a * b * c))$term.labels
[1] "a"     "b"     "c"     "a:b"   "a:c"   "b:c"   "a:b:c"




More information about the R-help mailing list