有没有一种方法可以在R中组合三个数组,以使第一个数组的第一行紧随第二个数组的第一行,然后是第三个数组的第三行?因此,如果我运行以下代码:
> number1<-rbind(rep("A",3), rep("B",3), rep("C",3))
> number1
[,1] [,2] [,3]
[1,] "A" "A" "A"
[2,] "B" "B" "B"
[3,] "C" "C" "C"
> number2<-rbind(rep(1,3), rep(2,3), rep(3,3))
> number2
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 2 2 2
[3,] 3 3 3
> number3<-rbind(rep("X",3), rep("Y",3), rep("Z",3))
> number3
[,1] [,2] [,3]
[1,] "X" "X" "X"
[2,] "Y" "Y" "Y"
[3,] "Z" "Z" "Z"
结果将如下所示:
[,1] [,2] [,3]
[1,] "A" "A" "A"
[2,] "1" "1" "1"
[3,] "X" "X" "X"
[4,] "B" "B" "B"
[5,] "2" "2" "2"
[6,] "Y" "Y" "Y"
[7,] "C" "C" "C"
[8,] "3" "3" "3"
[9,] "Z" "Z" "Z"
我已经尝试过融化,但是无法正常工作。
最佳答案
您可以尝试以下方法:
> matrix(t(cbind(number1,number2,number3)),ncol=3, byrow=T)
# [,1] [,2] [,3]
# [1,] "A" "A" "A"
# [2,] "1" "1" "1"
# [3,] "X" "X" "X"
# [4,] "B" "B" "B"
# [5,] "2" "2" "2"
# [6,] "Y" "Y" "Y"
# [7,] "C" "C" "C"
# [8,] "3" "3" "3"
# [9,] "Z" "Z" "Z"
关于arrays - 按行号组合3个数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32233623/