I have two dataframes and would like to filter the animals
column in table1
by the animals
column in table2
, while retaining the multiple categories of animals in table1
for cat and dog. The end result should appear the same as table1
, but with "lion" removed. There should still be two "cat" and two "dog".
I'm not sure how to approach this as an r newbie. I have a feeling the answer involves the match
function or some type of join? I would prefer a dplyr
or reshape2
method if possible, especially if there's a way to use a dplyr
join function. I'm also not very experienced with the merge
base function.
Here is the code for the two data frames:
table1 <- data.frame(id=c(1:7), animal=c("cat","cat","dog","dog","parakeet","lion","duck"))
table2 <- data.frame(id=c(1:4), animal=c("cat","dog","parakeet","duck"))