是否有办法将现有data.frame中的行名和列名连接到新数据框中。例如,我有(A,B,C)的列名和(1,2,3)的行名,我想将它们组合成一个3x3矩阵[A1,B1,C1; A2,B2,C2; A2,B2,C2]。谢谢你的帮助
答案 0 :(得分:10)
outer()
功能可以提供帮助:
> cn <- c("A","B","C")
> rn <- c("1","2","3")
> outer(cn, rn, function(x,y) paste(x,y,sep=""))
[,1] [,2] [,3]
[1,] "A1" "A2" "A3"
[2,] "B1" "B2" "B3"
[3,] "C1" "C2" "C3"
>