test1 <- as.matrix(c(1, 2, 3, 4, 5))
row.names(test1) <- c("a", "d", "c", "b", "e")
test2 <- as.matrix(c(6, 7, 8, 9, 10))
row.names(test2) <- c("e", "d", "c", "b", "a")
test1
[,1]
a 1
d 2
c 3
b 4
e 5
test2
[,1]
e 6
d 7
c 8
b 9
a 10
我该如何重新排序test2,使得行的顺序与test1相同?例如:
test2
[,1]
a 10
d 7
c 8
b 9
e 6
我尝试使用reorder函数:reorder(test1,test2),但我无法找到正确的语法。我发现reorder需要一个向量,而我在这里使用的是矩阵。我的真实数据有一个字符向量和另一个作为数据框架。我觉得数据结构对于上面的例子并不太重要,我只需要帮助解决语法问题,并能够将其适应到我的实际问题中。