I want to subset my dataframe by matching against string values in a list. My df looks like this:
df3:
functions main
1 burger_function (desc) c("burger", "fries", "coke", "onion rings", "cheese")
2 steak_function (desc) c("steak", "mash", "jack", "gravy", "cajun_fries")
3 chicken_function (desc) c("chicken", "salad", "sprite", "soup")
4 fish_function (desc) c("fish", "rice", "water", "garlic_bread")
My first column are functions with a description about them. I want to be able to search for a "main" value and subset the list to show which function it belongs to. So far I have tried this code but I am getting wrong values mixed in with the right ones. Is there a better way to accomplish this?
func_sub <- df3[sapply(df3$main, function(x) x %in% "fries"),]
To end up with something like this:
df3:
functions main
1 burger_function (desc) "fries"