Hi Alan,

you could also try the following function which has been submitted to s-news some time ago:

powerSet <- function(x){
if(length(x)==0) return(vector(mode(x), 0))
x <- sort(unique(x))
K <- NULL
for(m in x) K <- rbind(cbind(K, FALSE), cbind(K, TRUE))
out <- apply(K, 1, function(x, s) s[x], s=x)[-1]
names(out) <- NULL
return(out)
}

powerSet(1:5)

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
    http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Alan Simpson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 28, 2004 6:51 AM
Subject: [R] An index of all possible combinations of variables in a datafram e



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]]

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to