An embedded and charset-unspecified text was scrubbed... Name: n?o dispon?vel URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080720/dfc92af2/attachment.pl>
Can you give a small example of what you data looks like and what you think the output should be. Have you looked at 'combn'? On Sun, Jul 20, 2008 at 4:33 PM, lamack lamack <lamac_k at hotmail.com> wrote:> > Dear all, is there a R function that enumerate a partition of a vector of size n? (of course for n not very large). > I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 power n) includes de empty subset. > > Best Regards. > > ps. It is not a homework. I never posted homework in this list. > > LL > > > > _________________________________________________________________ > Cansado de espa?o para s? 50 fotos? Conhe?a o Spaces, o site de relac[[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
lamack lamack wrote:> Dear all, is there a R function that enumerate a partition of a vector of size n? (of course for n not very large). > I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 power n) includes de empty subset. > > Best Regards. > > ps. It is not a homework. I never posted homework in this list. > >The easiest way is probably to generate the numbers 1:(2^n-1), convert them to binary, and use the bits to indicate in/out status. E.g., n <- 4 x <- 1:(2^n-1) sapply(1:n, function(i) {r <- as.logical(x%%2) ; x <<- x%/%2 ; r}) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Try this replacing letters[1:4] with your set:> do.call(expand.grid, as.data.frame(rbind(letters[1:4], NA)))V1 V2 V3 V4 1 a b c d 2 <NA> b c d 3 a <NA> c d 4 <NA> <NA> c d 5 a b <NA> d 6 <NA> b <NA> d 7 a <NA> <NA> d 8 <NA> <NA> <NA> d 9 a b c <NA> 10 <NA> b c <NA> 11 a <NA> c <NA> 12 <NA> <NA> c <NA> 13 a b <NA> <NA> 14 <NA> b <NA> <NA> 15 a <NA> <NA> <NA> 16 <NA> <NA> <NA> <NA> On Sun, Jul 20, 2008 at 4:33 PM, lamack lamack <lamac_k at hotmail.com> wrote:> > Dear all, is there a R function that enumerate a partition of a vector of size n? (of course for n not very large). > I would like enumerate all the (2 power n)-1 sub-sets. (2 power n)-1 since (2 power n) includes de empty subset. > > Best Regards. > > ps. It is not a homework. I never posted homework in this list. > > LL > > > > _________________________________________________________________ > Cansado de espa?o para s? 50 fotos? Conhe?a o Spaces, o site de relac[[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >