在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)
使用gtools
包裹,
library(gtools)
x <- c(1,1,2,2,3)
permutations(5, 5, x, set = FALSE)
Run Code Online (Sandbox Code Playgroud)