我有一个矩阵 x
A B C D
1 11 12 13 14
2 21 22 23 24
3 31 32 33 34
4 41 42 43 44
5 51 52 53 54
和两个投票者
[,1] [,2]
[1,] "A" "B"
[2,] "A" "C"
[3,] "A" "D"
[4,] "B" "C"
[5,] "B" "D"
[6,] "C" "D"
我想要得到的是以下
Asset1 Asset2 Time Value1 Value2
A B 1 11 12
A B 2 21 22
A B 3 31 32
A B 4 41 42
A B 5 51 52
A C 1 11 13
A C 2 21 23
A C 3 31 33
A C 4 41 43
A C 5 51 53
A D 1 11 14
A D 2 21 24
A D 3 31 34
A D 4 41 44
A D 5 51 54
…
这是一个情节,我想要两种资产的每一种组合。不幸的是,我无法更改此表单的任何内容。
我试图用 reshape 包得到这个结果,但我无法解决这个问题。
这里还有一段获取初始矩阵的代码:
x <- matrix(c(11,12,13,14, 21,22,23,24 ,31,32,33,34, 41,42,43,44, 51,52,53,54), ncol=4, nrow=5, byrow=T)
colnames(x) <- c("A", "B", "C", "D")
rownames(x) <- 1:5
c <- matrix(c("A","B", "A","C", "A","D", "B", "C", "B", "D", "C", "D"), ncol=2, byrow=T)
谢谢您的帮助!