Skip to content
Prev 59644 / 398502 Next

Create a vector of combinations based on a table column names

Hi,

Here is something that does the job (though I am sure other people will 
find smarter solutions!):


 > samp=matrix(sample(0:1,size=100,replace=TRUE ,prob=c(0.8,0.2)),ncol=10)
 > colnames(samp)<-LETTERS[1:10]
 > unlist(lapply(apply(samp,1,FUN=function(vec) 
colnames(samp)[as.logical(vec)] ),paste,collapse=" "))
  [1] "A F J"   "D I"     "B I"     "A"       "G H"     "B C E H" "E 
H"     "B C E G" "E"
[10] "B C E I"

HTH,

Eric
At 16:40 23/11/2004, Henrik Andersson wrote:
Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

If the statistics are boring, then you've got the wrong numbers. -Edward 
Tufte