Search code examples
rsubset

Extract rows with similar rownames from two files


In R, how can extract rows with identical row names from two data frames?


Solution

  • If you have two data frames d1 and d2, the row names that are identical in both are given by intersect(rownames(d1), rownames(d2)). So you can do for example d1[intersect(rownames(d1), rownames(d2)), ] and get rows in d1 that exist in d2