我想按行名对几个表进行排序,行名的顺序相同,例如基于向量.
我的问题是,我不想按字母顺序排序,而是按特定的顺序排序.
此外,每个表的大小和行名都不相同,但它们的其余行名应该遵循相同的顺序.
Reproducible example个
### Initiating data
# Complete table with unordered rownames
tabComplete <- data.frame(Group=c("E", "A", "D", "B", "C"),
Values=c("order", "This", "correct", "is", "the"),
row.names=c("Fifth", "First", "Fourth", "Second", "Third"))
Group Values
Fifth E order
First A This
Fourth D correct
Second B is
Third C the
# Two tables that I would like to order by rownames
tabPortion1 <- tabComplete[c(1, 3, 5), ]
tabPortion2 <- tabComplete[c(1, 2, 4), ]
Group Values
Fifth E order
Fourth D correct
Third C the
Group Values
Fifth E order
First A This
Second B is
What I would like to achieve个
# Based on a vector, I would like that every table follow the same order but the have different sizes
vecMyOrder <- c("First", "Second", "Third", "Fourth", "Fifth")
# Tables with the correct order
tabComplete[c("First", "Second", "Third", "Fourth", "Fifth"), ]
tabPortion1[c("Third", "Fourth", "Fifth"), ]
tabPortion2[c("First", "Second", "Fifth"), ]
Group Values
First A This
Second B is
Third C the
Fourth D correct
Fifth E order
Group Values
Third C the
Fourth D correct
Fifth E order
Group Values
First A This
Second B is
Fifth E order
谢谢