Data
df1
col1
1 a
2 a
3 b
4 e
df2
col1 col2
1 1 a
2 1 c
3 1 c
4 1 e
5 2 a
6 2 b
7 2 b
8 2 e
9 3 a
10 3 a
11 3 b
12 3 e
I want to filter df2 using df1. So far I have this code.
filter(df2, any(col2==df1$col1[1]))
This allows me to filter row by row. But I want to filter by multiple rows. Not the whole df1 at once. I want to filter df2 using df1$col1[1:2]. So "a" followed by "a". I tried the following code but got this message.
filter(df2, col2==df1$col1[1] & col2==df1$col1[2])
[1] col1 col2 <0 rows> (or 0-length row.names)
Ideally output:
df2
col1 col2
1 3 a
2 3 a
3 3 b
4 3 e