Reputation: 2519
I am looking for dplyr's variant to the SQL where in
clause.
My goal is to look filter rows based upon their presence in a column of an other table. The code I have currently returns an error. I am guessing this is due to incorrectly pulling out the data from the second table to compare to the first.
Instruments %>% filter(name %in% distinct(Musician$plays_instrument))
I wrote an example similar to what I've got currently above this line. I am guessing that my mistake can be see in the syntax I am using. If not I can provide a working example if needed. Just takes some time to build it and I was hoping I got get this solved more quickly.
Upvotes: 1
Views: 498
Reputation: 887118
We can use subset
in base R
subset(Instruments, name %in% unique(Musician$plays_instrument))
Upvotes: 0
Reputation: 388982
Probably, you should use unique
since distinct
requires a dataframe as first argument.
library(dplyr)
Instruments %>% filter(name %in% unique(Musician$plays_instrument))
Upvotes: 1