如何在R中将排列创建为列表?
排列是与顺序的组合。例如,如果我们要创建一个带有数字序列的锁钥匙,那么它必须在某个方向上是有序的,否则,将很难记住并且容易解锁。通过使用combinat包的permn函数,我们可以找到一些数字或字符的排列。
加载combinat软件包-
library(combinat)
创建排列列表的示例-
permn(LETTERS[1:4])[[1]]
[1] "A" "B" "C" "D"
[[2]]
[1] "A" "B" "D" "C"
[[3]]
[1] "A" "D" "B" "C"
[[4]]
[1] "D" "A" "B" "C"
[[5]]
[1] "D" "A" "C" "B"
[[6]]
[1] "A" "D" "C" "B"
[[7]]
[1] "A" "C" "D" "B"
[[8]]
[1] "A" "C" "B" "D"
[[9]]
[1] "C" "A" "B" "D"
[[10]]
[1] "C" "A" "D" "B"
[[11]]
[1] "C" "D" "A" "B"
[[12]]
[1] "D" "C" "A" "B"
[[13]]
[1] "D" "C" "B" "A"
[[14]]
[1] "C" "D" "B" "A"
[[15]]
[1] "C" "B" "D" "A"
[[16]]
[1] "C" "B" "A" "D"
[[17]]
[1] "B" "C" "A" "D"
[[18]]
[1] "B" "C" "D" "A"
[[19]]
[1] "B" "D" "C" "A"
[[20]]
[1] "D" "B" "C" "A"
[[21]]
[1] "D" "B" "A" "C"
[[22]]
[1] "B" "D" "A" "C"
[[23]]
[1] "B" "A" "D" "C"
[[24]]
[1] "B" "A" "C" "D"
permn(c("Aluminium","Calcium","Carbon","Nitrogen"))
[[1]]
[1] "Aluminium" "Calcium" "Carbon" "Nitrogen"
[[2]]
[1] "Aluminium" "Calcium" "Nitrogen" "Carbon"
[[3]]
[1] "Aluminium" "Nitrogen" "Calcium" "Carbon"
[[4]]
[1] "Nitrogen" "Aluminium" "Calcium" "Carbon"
[[5]]
[1] "Nitrogen" "Aluminium" "Carbon" "Calcium"
[[6]]
[1] "Aluminium" "Nitrogen" "Carbon" "Calcium"
[[7]]
[1] "Aluminium" "Carbon" "Nitrogen" "Calcium"
[[8]]
[1] "Aluminium" "Carbon" "Calcium" "Nitrogen"
[[9]]
[1] "Carbon" "Aluminium" "Calcium" "Nitrogen"
[[10]]
[1] "Carbon" "Aluminium" "Nitrogen" "Calcium"
[[11]]
[1] "Carbon" "Nitrogen" "Aluminium" "Calcium"
[[12]]
[1] "Nitrogen" "Carbon" "Aluminium" "Calcium"
[[13]]
[1] "Nitrogen" "Carbon" "Calcium" "Aluminium"
[[14]]
[1] "Carbon" "Nitrogen" "Calcium" "Aluminium"
[[15]]
[1] "Carbon" "Calcium" "Nitrogen" "Aluminium"
[[16]]
[1] "Carbon" "Calcium" "Aluminium" "Nitrogen"
[[17]]
[1] "Calcium" "Carbon" "Aluminium" "Nitrogen"
[[18]]
[1] "Calcium" "Carbon" "Nitrogen" "Aluminium"
[[19]]
[1] "Calcium" "Nitrogen" "Carbon" "Aluminium"
[[20]]
[1] "Nitrogen" "Calcium" "Carbon" "Aluminium"
[[21]]
[1] "Nitrogen" "Calcium" "Aluminium" "Carbon"
[[22]]
[1] "Calcium" "Nitrogen" "Aluminium" "Carbon"
[[23]]
[1] "Calcium" "Aluminium" "Nitrogen" "Carbon"
[[24]]
[1] "Calcium" "Aluminium" "Carbon" "Nitrogen"
permn(c(1,2,3))
[[1]]
[1] 1 2 3
[[2]]
[1] 1 3 2
[[3]]
[1] 3 1 2
[[4]]
[1] 3 2 1
[[5]]
[1] 2 3 1
[[6]]
[1] 2 1 3
以上是 如何在R中将排列创建为列表? 的全部内容, 来源链接: utcz.com/z/330891.html