[R] An index of all possible combinations of variables in a d ata frame
Liaw, Andy
andy_liaw at merck.com
Tue Sep 28 14:25:49 CEST 2004
This might be a bit of an abuse of the functions, but it seems to work:
> dat <- data.frame(A=1, B=2, C=3)
> f <- ~ .^3
> colnames(attr(terms(f, data=dat), "factors"))
[1] "A" "B" "C" "A:B" "A:C" "B:C" "A:B:C"
Cheers,
Andy
> From: Alan Simpson
>
> Hello list
>
> 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?
>
> Any help would be greatly appreciated.
>
> Regards
>
> Alan Simpson
> Roberts Research Group
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list