对于具有3行和3列的给定输入矩阵,
1 2 3
5 6 7
7 8 9
制定矩阵,其中矩阵包含&在任何两个元素之间,即具有5行和3列的矩阵
1 & 2 & 3
5 & 6 & 7
7 & 8 & 9
是否有直接制定后一种矩阵的命令?
答案 0 :(得分:1)
假设你的矩阵被称为mat
:
t(apply(mat, 2, rbind, "&")[-ncol(mat) * 2, ])
# [,1] [,2] [,3] [,4] [,5]
# [1,] "1" "&" "2" "&" "3"
# [2,] "4" "&" "5" "&" "6"
# [3,] "7" "&" "8" "&" "9"