RE: [R] Create a vector of combinations based on a table column names

2004-11-23 Thread Andy Bunn
There has to be a better (more readable) way, but this works... > set.seed(323) > foo.df <- data.frame(A = round(runif(5)), B = round(runif(5)), C = round(runif(5))) > foo.df A B C 1 0 1 1 2 1 1 1 3 1 1 1 4 0 1 1 5 1 1 0 > names.list <- lapply( apply( foo.df, 1, function( x ) colnames( foo.df )[

Re: [R] Create a vector of combinations based on a table column names

2004-11-23 Thread Eric Lecoutre
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,c