Permute all unique enumerations of a vector in R

前端 未结 7 797
忘了有多久
忘了有多久 2020-11-29 06:21

I\'m trying to find a function that will permute all the unique permutations of a vector, while not counting juxtapositions within subsets of the same element type.

7条回答
  •  伪装坚强ぢ
    2020-11-29 06:27

    One option that hasn't been mentioned here is the allPerm function from the multicool package. It can be used pretty easily to get all the unique permutations:

    library(multicool)
    perms <- allPerm(initMC(dat))
    dim(perms)
    # [1] 18900    10
    head(perms)
    #      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
    # [1,]    4    4    3    3    1    1    0    0    0     0
    # [2,]    0    4    4    3    3    1    1    0    0     0
    # [3,]    4    0    4    3    3    1    1    0    0     0
    # [4,]    4    4    0    3    3    1    1    0    0     0
    # [5,]    3    4    4    0    3    1    1    0    0     0
    # [6,]    4    3    4    0    3    1    1    0    0     0
    

    In benchmarking I found it to be faster on dat than the solutions from the OP and daroczig but slower than the solution from Aaron.

提交回复
热议问题