R:Binary matrix for all possible unique results

后端 未结 3 1417
孤独总比滥情好
孤独总比滥情好 2020-12-18 06:02

How to generate a binary matrix for all possible permutations of \'i\' variables X, where \" i \" can be any number between 1 and infinite. Resultant matrix will have 2^ i u

3条回答
  •  一向
    一向 (楼主)
    2020-12-18 06:34

    The fonction combos of the package hier.part will do the job I think.

    require(hier.part)
    combos(2)$binary
         [,1] [,2]
    [1,]    1    0
    [2,]    0    1
    [3,]    1    1
    
    combos(3)$binary
         [,1] [,2] [,3]
    [1,]    1    0    0
    [2,]    0    1    0
    [3,]    0    0    1
    [4,]    1    1    0
    [5,]    1    0    1
    [6,]    0    1    1
    [7,]    1    1    1
    

    Except that you will have to add the "null" combination. HTH

提交回复
热议问题