I have a two dataframes of names, where dataframe one contains a single column of names whereas dataframe two contains multiple columns of names. How can I filter the second dataframe to only contain rows that have a match in the first dataframe?
ex/
df1
| names |
|---|
| John |
| Joan |
df2
| Column A | Column B | Column C | Column D |
|---|---|---|---|
| Gerry | Jim | Brian | Joan |
| John | John | John | John |
| Ron | Greg | Sam | Maisy |
desired output
| names | Column A | Column B | Column C | Column D |
|---|---|---|---|---|
| Joan | Gerry | Jim | Brian | Joan |
| John | John | John | John | John |
I've tried using a left_join from dplyr but the output was not what I needed
df1doesn't make a lot of sense since if you have "Joan" in column B row 2 instead of "John", and "John" instead of "Jim" in row 1, then there is no unique correspondence to the rows of df2 (you could easily argue that the first column should have "John" and "Joan" instead of "Joan" and "John").