I'm trying to compare columns from two data frames to extract items that appear in both. Specifically:
df1:
state group species
1 CA 2 cat, dog, chicken, mouse
2 CA 1 cat
3 NV 1 dog, chicken
4 NV 2 chicken
5 WA 1 chicken, rat, mouse, lion
6 WA 2 dog, cat
7 WA 3 dog, chicken
8 WA 4 cat, chicken
df2:
state special_species
1 CA cat
2 CA chicken
3 CA mouse
4 WA cat
5 WA chicken
6 NV dog
I'm interested in determining which of the special_species
from df2
are present in df1
. I'd like a new dataframe that has the state, group, and the special species. I think it should be a combination of a join, group_by
, and summarize
, but I can't seem to get that to work.