I need to generate a {0,1} matrix wifht nCr rows and n columns. The rows of the matrix will consist of all possible combinations containing r ones.
My clumsy attempt for n = 6 and r = 3 is X <- expand.grid(c(1,0),c(1,0),c(1,0),c(1,0),c(1,0),c(1,0)) Y <- X[rowSums(X)==3,] I can genralize this in a function but the result is quite ugly. Any suggestions? Thank you in advance. Martin [[alternative HTML version deleted]] ______________________________________________ R-help@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 and provide commented, minimal, self-contained, reproducible code.