I have two dataframes. I would like to match the rownames of the two dataframes, and if the rownames won't match, I would like to remove theses rows from both dataframe to match the dimension of rows.
Dataframe A:
5002T 0 1
B01167 1 0
C1329 1 0
dim(3, 3)
Dataframe B:
5002T 4
B41167 3
C1329 8
2C134 1
dim(4, 2)
The Output will be look like the following:
Dataframe A_New:
5002T 0 1
C1329 1 0
dim(2, 3)
Dataframe B_New:
5002T 4
C1329 8
dim(2, 2)
Here is the code which I have tried to match the rownames:
match <- rownames(A) %in% rownames(B)
sum(!match)
How can I remove the unmatched rows from both dataframes and get the same dimension.