Subset data using information from another data frame [r]

I have two data frames. One contains a large amount of data. The second contains less 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 data from data frame A using row.names from data frame B to create:

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

Basically, I want to use to group names from data frame B into a subset of data from data frame A, which has the same row names.

Any help would be appreciated.

0
source share
1 answer

Have you tried A[rownames(B),]?? (I assume that you are really referring to row names, not to columns called "Row.names")

+2
source

All Articles