I have two dataframes:
df1 <- data.frame(cola = c("dum1", "dum2", "dum3"), colb = c("bum1", "bum2", "bum3"), colc = c("cum1", "cum2", "cum3"))
and:
df2 <- data.frame(cola = c("dum1", "dum2", "dum4"), colb = c("bum1", "bum2", "bum3"))
I need to find the indices of the rows in dataframe df1
in which the columns cola
and colb
are the same, here it would be row 1 and row 2. I know the inner_join
function from the dplyr
package but this results in a new dataframe. I just need a vector with the indices. I could do this with which
for each column needed but this would be ugly if I need to find common rows based on a large number of columns.
Any help is much appreciated.