Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 R 中,如何从两个数据框中提取具有相同行名的行?
谢谢。SM
如果您有两个数据框d1和d2,则两者中相同的行名称由 给出intersect(rownames(d1), rownames(d2))。因此,您可以做例如d1[intersect(rownames(d1), rownames(d2)), ]并获取d1其中存在的行d2
d1
d2
intersect(rownames(d1), rownames(d2))
d1[intersect(rownames(d1), rownames(d2)), ]