title: Reverse lookup for loop in R
body: <p>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.</p>
  
  <p>Consider the following dataset</p>
  
  <pre><code>ingredients &lt;- c('N/A', 'cat', 'bird')
  product &lt;- c('cat', 'bird', 'dog')
  data &lt;- data.frame(ingredients, product)
  head(data)
  </code></pre>
  
  <p>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).</p>
  
  <p>It seems like some of sort of for loop that appends is the right approach. </p>
  
  <pre><code>needed &lt;- list()
  
  for (product in list){
  
    needed[[product]]&lt;-df
  }
  
  df &lt;- dplyr::bind_rows(product)
  </code></pre>