I have a set of numbers / string that makes other number / string. I need to create a function that gives me a list of the all the numbers / string needed to create that number / string.
Consider the following dataset
ingredients <- c('N/A', 'cat', 'bird')
product <- c('cat', 'bird', 'dog')
data <- data.frame(ingredients, product)
head(data)
If I input function(dog), I would like a list that returns bird and then cat. The function knows when to stop when ingredients = N/A (there's nothing more to look up).
It seems like some of sort of for loop that appends is the right approach.
needed <- list()
for (product in list){
needed[[product]]<-df
}
df <- dplyr::bind_rows(product)