I'd appreciate it if you'd keep on list for the archives. That said, I think this function does what you were hoping for.
Michael powerset <- function(n, items = NULL){ if(!is.null(items)) { if(n != length(items)) warning("Resetting n in preference to length(items)") n = length(items) } smat <- do.call(expand.grid, rep(list(c(0,1)), n)) if(!is.null(items)) smat <- smat * matrix(items, ncol = n, nrow = 2^n, byrow = T) smat } On Sat, Nov 19, 2011 at 8:49 PM, Gyanendra Pokharel <gyanendra.pokha...@gmail.com> wrote: > Hi Michael, > I have trouble to find the subsets of a given set. For example x <- c(2, 3, > 4, 5), there will be 16 subsets of this set > in the matrix form > 0 0 0 0 > 1 0 0 0 > 0 1 0 0 > 0 0 1 0 > 0 0 0 1 > 1 1 0 0 > 0 1 1 0 > 0 0 1 1 > 0 1 0 1 > 1 0 1 0 > 1 0 1 1 > 1 1 1 0 > 0 1 1 1 > 1 0 1 1 > 1 1 0 1 > 1 1 1 1 > times transpose(x) , but how could I produce in R? > Thanks in advance ______________________________________________ R-help@r-project.org 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.