I'm trying to filter a data set that has a list as one of the variables. Is there a way to do this elegantly with the tidyverse, if no, what's a reasonable way of doing this?
Ideally, the last line would return a df with the 3 rows where color was red, orange, and purple, instead of just returning the whole data frame (I'm assuming this is because "red" is in the color_base variable).
This is great for a one-off solution, but if I wanted to find all the elements with yellow, I'd need to make another function.
Is there a way to make this work in a more generalized manner?
Ideally one where I could use the function below, and then specify many 'targets', so that i could reuse the function and not have to create a new function every time.
In our example, wasn't each row unique to begin with?
Running the code without group_by(color) doesn't seem to change the results, and if there were two rows with the same color name, but different 'base colors" couldn't this lead to unpredictable results?
Well, I was wrong. I thought I checked that the group_by was necessary before I first posted the solution but I must have made some other mistake. Thanks for pointing that out.