I have a list of 10 columns called food.1, food.2... food.10, and was wanting to filter my data for when the food name in any of these 10 columns matched a pre-specified list of carbohydrate foods (bread, rice, potatoes, cake, dough)
I started to write this code below, but I am sure there is an easier way to do it rather than copying out every column for every possible artery name I want to keep. Would a function of sorts work, and how so would this be written?
carb.df= df %>%
filter(food.1 =="bread"|food.2 =="bread"|
food.3=="bread"|food.4 =="bread"|
food.5 =="bread"|food.6 =="bread"|
food.7 =="bread"|food.8 =="bread"|
food.9 =="bread"|food.10 =="bread"|
food.1 =="rice"|food.2 =="rice"|
food.3=="rice"|food.4 =="rice"|
food.5 =="rice"|food.6 =="rice"|
food.7 =="rice"|food.8 =="rice"|
food.9 =="rice"|food.10 =="rice"|
food.1 =="cake"|food.2 =="cake"|
food.3 =="cake"|food.4 =="cake"|
food.5 =="cake"|food.6 =="cake"|
food.7 =="cake"|food.8 =="cake"|
food.9 =="cake"|food.10 =="cake")