[R] Function for all 2^N subsets of N

(Ted Harding) Ted.Harding at manchester.ac.uk
Tue Sep 1 10:42:21 CEST 2009


On 01-Sep-09 08:33:41, Gerrit Eichner wrote:
> Maybe
> 
> expand.grid( rep( list( 0:1), 10))
> 
> does what you want.
>   Best regards  --  Gerrit

Thanks! That does seem to do the job. I hadn't thought of expand.grid().
Ted.

> On Tue, 1 Sep 2009, 
> Ted.Harding at manchester.ac.uk wrote:
> 
>> Greetings all!
>> I have been searching the Site for a function, say "subsets",
>> such that for instance
>>
>>  subsets(10)
>>
>> would return a (say) matrix of indices to the 2^10 subsets of
>> N items -- perhaps in the form of 2^10 rows each of which is
>> 10 entries each either TRUE or FALSE. Or 1 or 0. Or ...
>>
>> I can of course write my own, using good old looping technology
>> or similar, but it would be good to find one which did it quick
>> and snappy, at the compiled level.
>>
>> A Site Search in Function on "all subsets" didn't seem to yield
>> anything of the kind, which surprised me. Maybe I overlooked
>> something ...
>>
>> (This is prompted by the recent "OT" discussion on "HT vs. HH",
>> to which I want to respond later).
>>
>> With thanks,
>> Ted.
>>
>> --------------------------------------------------------------------
>> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 01-Sep-09                                       Time: 09:09:09
>> ------------------------------ XFMail ------------------------------
>>
>> ______________________________________________
>> 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.
>>
> 
> ______________________________________________
> 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.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 01-Sep-09                                       Time: 09:42:18
------------------------------ XFMail ------------------------------




More information about the R-help mailing list