R语言 生成行和列中都没有重复元素的排列

gpfsuwkq  于 2023-09-27  发布在  其他
关注(0)|答案(4)|浏览(94)

我有4支球队(A-D)和4场比赛(1-4)。
目标:我想生成一个dataframe(4,4):

  • 四排四轮
  • 有四个栏目,四场比赛
  • 我想在这4行/轮中为每列/游戏分配一个不同的团队
  • 并且我不希望行或列中有重复项

我知道如何进行排列,我知道如何避免每行中的重复,但当我试图避免行和列中的重复时,我被卡住了。
最后,我想得到一个像这样的 Dataframe (没有水平或垂直重复):

A B C D

B D A C

D C B A

C A D B

显然,在现实中,我有更多的游戏和团队!
有人能帮我吗?
谢谢你,谢谢!

编辑:

感谢你们所有人!超级有用。
我也希望能够在我得到的输出中修复一些位置(最后一个是12场比赛和12支球队)。
例如,我希望能够指定几个固定位置,例如:B必须在位置(1,2)***AND**D必须在位置(4,3)ANDetc*.
你知道如何得到满足这些条件的拉丁方吗?

13z8s7eq

13z8s7eq1#

我认为你的问题相当于在向量中循环。即,从ABCD开始,移动一个BCDA,等等。我们可以这样做,例如。像这样:

x <- LETTERS[1:4]
sapply(seq_along(x), \(i) x[c(i:length(x), seq_len(i - 1))])
[,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D" 
[2,] "B"  "C"  "D"  "A" 
[3,] "C"  "D"  "A"  "B" 
[4,] "D"  "A"  "B"  "C"
7vux5j2d

7vux5j2d2#

行或列中没有重复对我来说听起来像Latin square
magic软件包可能对此有所帮助

magic::rlatin(n = 3)
#>      [,1] [,2] [,3]
#> [1,]    2    1    3
#> [2,]    1    3    2
#> [3,]    3    2    1

对于您的示例,我们可以使用现有的带有字母或团队名称的x,然后转换为 Dataframe 。

x <- LETTERS[1:4]
as.data.frame(matrix(x[magic::rlatin(length(x))], nrow = length(x)))
#>   V1 V2 V3 V4
#> 1  D  B  A  C
#> 2  A  D  C  B
#> 3  B  C  D  A
#> 4  C  A  B  D

这取决于用例,如果你想需要一个完整的其他包,特别是当一个很好的答案,如何做到这一点,在基地R已经提交。

7z5jn7bk

7z5jn7bk3#

随机一个示例

如果你只需要一个随机的拉丁方阵,你可以定义一个函数如下

RandLatinSqr <- function(v) {
    # check if the resulting matrix is valid
    checker <- function(m) {
        all(table(m, col(m)) == 1)
    }
    #  repeat random generation until one valid matrix occurs
    repeat {
        m <- t(replicate(length(v), sample(v)))
        if (checker(m)) {
            return(m)
        }
    }
}

或更轻(* 更高效 *)的embed版本

RandLatinSqr2 <- function(v) {
    embed(
        rep(v, length.out = 2 * length(v) - 1),
        length(v)
    )[sample(seq_along(v)), ]
}

你可以得到一个矩阵

> RandLatinSqr(LETTERS[1:4])
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "D"  "B"
[3,] "C"  "D"  "B"  "A"
[4,] "B"  "A"  "C"  "D"

> RandLatinSqr2(LETTERS[1:4])
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

所有有效矩阵

如果你没有大量的团队,你绝对可以使用蛮力方法来枚举所有的拉丁方块。因为你只有**4**队,所以我不认为所有排列都会消耗太多时间,即choose(prod(1:4), 4) * prod(1:4) = 255024排列。
例如,我们可以运行下面的代码

library(pracma)
AllLatinSqr <- function(v) {
    L <- perms(v) # all permutations of above 4 teams

    # check if the resulting matrix is valid
    checker <- function(m) {
        all(table(m, col(m)) == 1)
    }

    # all valid matrices
    unlist(Filter(
        length,
        combn(1:nrow(L),
            length(v),
            FUN = \(x) {
                m <- L[x, ]
                if (checker(m)) {
                    apply(
                        perms(1:nrow(m)),
                        1,
                        \(k) m[k, ],
                        simplify = FALSE
                    )
                }
            }, simplify = FALSE
        )
    ), recursive = FALSE)
}

或基于RandLatinSqr2的***更高效的***版本(由于所有拉丁方在行/列排列的意义上都是均匀可变的)***

AllLatinSqr2 <- function(v) {
    RandLatinSqr2 <- function(v) {
        embed(
            rep(v, length.out = 2 * length(v) - 1),
            length(v)
        )[sample(seq_along(v)), ]
    }

    m <- RandLatinSqr2(v)
    L <- asplit(perms(seq_along(v)), 1)
    unlist(lapply(L, \(i) lapply(L, \(j) m[i, j])), recursive = FALSE)
}

或者你可以定义一个自定义函数(base R),如下所示

AllLatinSqr3 <- function(v) {
    # check valid values to fill in the given position of matrix
    checker <- function(mat, i, j, v) {
        setdiff(v, na.omit(c(mat[i, ], mat[, j])))
    }
    
    # help to generate all possible matrices
    helper <- function(m, idx, v) {
        l <- length(v)
        i <- (idx - 1) %/% l + 1
        j <- (idx - 1) %% l + 1
        u <- checker(m, i, j, v)
        lapply(u, \(x) {
            m[i, j] <- x
            m
        })
    }

    # initial value
    lst <- list(matrix(NA, length(v), length(v)))
    cnt <- 1
    repeat {
        lst <- unlist(
            lapply(
                lst,
                helper,
                idx = cnt,
                v = v
            ),
            recursive = FALSE
        )
        if (cnt == length(v)^2) {
            return(lst)
        } else {
            cnt <- cnt + 1
        }
    }
}

标杆管理

v <- LETTERS[1:3]
microbenchmark(
    AllLatinSqr(v),
    AllLatinSqr2(v),
    AllLatinSqr3(v),
    unit = "relative"
)

Unit: relative
            expr      min       lq      mean    median       uq      max neval
  AllLatinSqr(v) 25.35247 22.62071 16.718686 22.735617 23.99345 1.801778   100
 AllLatinSqr2(v)  1.00000  1.00000  1.000000  1.000000  1.00000 1.000000   100
 AllLatinSqr3(v) 13.23587 10.86634  8.252907  9.725716 10.83098 3.323076   100
iszxjhcz

iszxjhcz4#

关于你最近编辑的带有约束的问题,例如,BD分别固定在(1,2)(4,3)的位置,你可以有以下两个基于AllLatinSqrtConstr2AllLatinSqrtConstr3的变体。
请注意,类似的想法可以应用于RandLatinSqr,因此在此答案中跳过。

代码

AllLatinSqrConstr2 <- function(v) {
    RandLatinSqr2 <- function(v) {
        embed(
            rep(v, length.out = 2 * length(v) - 1),
            length(v)
        )[sample(seq_along(v)), ]
    }

    constrFilter <- function(m) {
        m[1, 2] == "B" && m[4, 3] == "D"
    }

    m <- RandLatinSqr2(v)
    L <- asplit(perms(seq_along(v)), 1)

    Filter(
        constrFilter,
        unlist(lapply(L, \(i) lapply(L, \(j) m[i, j])), recursive = FALSE)
    )
}

AllLatinSqrConstr3 <- function(v) {
    # check valid values to fill in the given position of matrix
    checker <- function(mat, i, j, v) {
        setdiff(v, na.omit(c(mat[i, ], mat[, j])))
    }

    # help to generate all possible matrices
    helper <- function(m, idx, v) {
        l <- length(v)
        i <- (idx - 1) %/% l + 1
        j <- (idx - 1) %% l + 1
        if (is.na(m[i, j])) {
            u <- checker(m, i, j, v)
            lapply(u, \(x) {
                m[i, j] <- x
                m
            })
        } else {
            list(m)
        }
    }

    # initial value
    m <- matrix(NA, length(v), length(v))
    m[1, 2] <- "B"
    m[4, 3] <- "D"
    lst <- list(m)
    cnt <- 1
    repeat {
        lst <- unlist(
            lapply(
                lst,
                helper,
                idx = cnt,
                v = v
            ),
            recursive = FALSE
        )
        if (cnt == length(v)^2) {
            return(lst)
        } else {
            cnt <- cnt + 1
        }
    }
}

输出

给定输入数据v <- LETTERS[1:4]

> AllLatinSqrConstr2(v)
[[1]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "A"  "C"
[4,] "A"  "C"  "D"  "B"

[[2]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "A"  "B"  "C"
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "C"  "D"  "A"

[[3]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "C"  "A"  "B"  "D" 
[4,] "A"  "C"  "D"  "B"

[[4]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "A"  "B"  "C"
[4,] "B"  "C"  "D"  "A"

[[5]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[6]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A"
[3,] "A"  "C"  "B"  "D" 
[4,] "C"  "A"  "D"  "B"

[[7]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "A"  "D"  "C"

[[8]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "C"  "A"  "D"  "B"

[[9]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "A"  "D"  "C" 

[[10]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "C"  "A"  "D"  "B"

[[11]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "A"  "B"  "C"
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "C"  "D"  "A"

[[12]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "A"  "C"
[4,] "A"  "C"  "D"  "B"

[[13]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "A"  "B"  "C"
[4,] "B"  "C"  "D"  "A"

[[14]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "C"  "A"  "B"  "D"
[4,] "A"  "C"  "D"  "B"

[[15]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[16]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A"
[3,] "A"  "C"  "B"  "D"
[4,] "C"  "A"  "D"  "B"

[[17]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "C"  "A"  "D"  "B"

[[18]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "A"  "D"  "C"

[[19]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A"
[3,] "A"  "C"  "B"  "D"
[4,] "C"  "A"  "D"  "B"

[[20]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[21]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "C"  "A"  "B"  "D"
[4,] "A"  "C"  "D"  "B" 

[[22]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "A"  "B"  "C"
[4,] "B"  "C"  "D"  "A"

[[23]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "A"  "C"
[4,] "A"  "C"  "D"  "B"

[[24]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "A"  "B"  "C" 
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "C"  "D"  "A"

[[25]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[26]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A"
[3,] "A"  "C"  "B"  "D"
[4,] "C"  "A"  "D"  "B"

[[27]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "C"  "A"  "B"  "D" 
[4,] "A"  "C"  "D"  "B"

[[28]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "A"  "B"  "C"
[4,] "B"  "C"  "D"  "A"

[[29]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "A"  "D"  "C"

[[30]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "C"  "A"  "D"  "B"

[[31]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "A"  "C"
[4,] "A"  "C"  "D"  "B"

[[32]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "A"  "B"  "C"
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "C"  "D"  "A"

> AllLatinSqrConstr3(v)
[[1]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "B"  "D"  "A"  "C"
[3,] "D"  "C"  "B"  "A"
[4,] "C"  "A"  "D"  "B"

[[2]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "A"  "B"  "C" 
[4,] "B"  "C"  "D"  "A"

[[3]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "A"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[4]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "C"  "D"  "B"  "A"
[3,] "D"  "C"  "A"  "B"
[4,] "B"  "A"  "D"  "C"

[[5]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "A"  "B"  "C"
[3,] "C"  "D"  "A"  "B" 
[4,] "B"  "C"  "D"  "A"

[[6]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "C"  "A"  "B"
[3,] "C"  "D"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[7]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "B"  "D"  "A"  "C"
[4,] "C"  "A"  "D"  "B"

[[8]]
     [,1] [,2] [,3] [,4]
[1,] "A"  "B"  "C"  "D"
[2,] "D"  "C"  "B"  "A" 
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "A"  "D"  "C"

[[9]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "B"  "C"
[3,] "D"  "A"  "C"  "B"
[4,] "B"  "C"  "D"  "A"

[[10]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "A"  "B"  "C" 
[4,] "B"  "C"  "D"  "A"

[[11]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "A"  "D"  "C"  "B"
[3,] "D"  "C"  "B"  "A"
[4,] "B"  "A"  "D"  "C"

[[12]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "B"  "D"  "C"  "A"
[3,] "D"  "A"  "B"  "C"
[4,] "A"  "C"  "D"  "B"

[[13]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "A"  "B"  "C" 
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "C"  "D"  "A"

[[14]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "A"  "B"  "C"
[3,] "B"  "D"  "C"  "A"
[4,] "A"  "C"  "D"  "B"

[[15]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "A"  "C"  "B"
[3,] "A"  "D"  "B"  "C"
[4,] "B"  "C"  "D"  "A" 

[[16]]
     [,1] [,2] [,3] [,4]
[1,] "C"  "B"  "A"  "D"
[2,] "D"  "C"  "B"  "A"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "A"  "D"  "C"

[[17]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "C"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "C"  "A"  "D"  "B"

[[18]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "A"  "D"  "C"  "B" 
[3,] "C"  "A"  "B"  "D"
[4,] "B"  "C"  "D"  "A"

[[19]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "A"  "C"  "D"
[3,] "C"  "D"  "B"  "A"
[4,] "A"  "C"  "D"  "B"

[[20]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A" 
[3,] "A"  "C"  "B"  "D"
[4,] "C"  "A"  "D"  "B"

[[21]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "B"  "D"  "C"  "A"
[3,] "C"  "A"  "B"  "D"
[4,] "A"  "C"  "D"  "B"

[[22]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "C"  "A"  "B"  "D"
[3,] "A"  "D"  "C"  "B"
[4,] "B"  "C"  "D"  "A"

[[23]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "C"  "A"
[4,] "A"  "C"  "D"  "B"

[[24]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "A"  "C"
[2,] "C"  "D"  "B"  "A"
[3,] "B"  "A"  "C"  "D"
[4,] "A"  "C"  "D"  "B"

[[25]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "A"  "C"  "B"  "D" 
[3,] "B"  "D"  "A"  "C"
[4,] "C"  "A"  "D"  "B"

[[26]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "A"  "C"  "B"  "D"
[3,] "C"  "D"  "A"  "B"
[4,] "B"  "A"  "D"  "C"

[[27]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "A"  "D"  "B"  "C"
[3,] "B"  "C"  "A"  "D"
[4,] "C"  "A"  "D"  "B"

[[28]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "C"  "A"  "D"
[3,] "A"  "D"  "B"  "C"
[4,] "C"  "A"  "D"  "B"

[[29]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "A"  "C"  "B"  "D"
[4,] "C"  "A"  "D"  "B"

[[30]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "B"  "D"  "A"  "C"
[3,] "C"  "A"  "B"  "D"
[4,] "A"  "C"  "D"  "B"

[[31]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "A"  "B"  "D"
[3,] "B"  "D"  "A"  "C"
[4,] "A"  "C"  "D"  "B"

[[32]]
     [,1] [,2] [,3] [,4]
[1,] "D"  "B"  "C"  "A"
[2,] "C"  "D"  "A"  "B"
[3,] "A"  "C"  "B"  "D"
[4,] "B"  "A"  "D"  "C"

相关问题