重复排列

Nic*_*ick 1 r permutation

在R中,我如何产生一个组的所有排列,但在这个组中有一些重复的元素.

示例:

A = {1,1,2,2,3} 
Run Code Online (Sandbox Code Playgroud)

方案:

1,1,2,2,3
1,1,2,3,2
1,1,3,2,2
1,2,1,2,3
1,2,2,1,3
1,2,2,3,1
.
.
Run Code Online (Sandbox Code Playgroud)

Ben*_*nes 5

使用gtools包裹,

library(gtools)

x <- c(1,1,2,2,3)

permutations(5, 5, x, set = FALSE)
Run Code Online (Sandbox Code Playgroud)