简体   繁体   English

使用来自不同数据帧的信息子集数据[r]

[英]Subset data using information from a different data frame [r]

I have two data frames. 我有两个数据帧。 One contains a large amount of data. 一个包含大量数据。 The second contains a smaller amount of data with some matching row names. 第二个包含较少量的数据,其中包含一些匹配的行名。

data frame A
Row.names  data
    1       A
    2       B
    3       C
    4       D
    5       E

data frame B
Row.names  data
    1       X
    3       Y
    5       Z

I want to extract the data from data frame A using the row.names from data frame B to create: 我想使用数据框B中的row.names从数据框A中提取数据来创建:

data frame C
Row.names   data
    1        A
    3        C
    5        E

I basically want to use to row names from data frame B to subset data from data frame A that has the exact same row names. 我基本上想要使用从数据帧B的行名称到具有完全相同的行名称的数据帧A的子集数据。

Any help would be appreciated. 任何帮助,将不胜感激。

Did you try A[rownames(B),] ?? 你试过A[rownames(B),] ?? (I am assuming that you are really referring to row names, not to columns called "Row.names") (我假设你实际上是指行名,而不是名为“Row.names”的列)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM