title: How to select value from one column based on values from different column?
body: <p>I have a list of characters as such:</p>
  <pre><code>list &lt;- c(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;)
  </code></pre>
  <p>and I have a df as such:</p>
  <pre><code>df = tibble(animal = c(&quot;dog&quot;, &quot;fish&quot;, &quot;frog&quot;, &quot;cat&quot;, &quot;shark&quot;), plant = c(&quot;tree&quot;, &quot;daisy&quot;, &quot;mushroom&quot;, &quot;grass&quot;, &quot;dafodil&quot;))
  
  print(df)
  
  # A tibble: 5 × 2
    animal plant   
    &lt;chr&gt;  &lt;chr&gt;   
  1 dog    tree    
  2 fish   daisy   
  3 frog   mushroom
  4 cat    grass   
  5 shark  dafodil
  </code></pre>
  <p>I would like to generate a list of plants corresponding to the list of animals above, which would look like :</p>
  <pre><code>plant_list 
  c(&quot;tree&quot;, &quot;grass&quot; &quot;daisy&quot;)
  </code></pre>
  <p>I have tried</p>
  <pre><code>plant_list &lt;- c()
  
  for (i in list){
    if (df$animal == i){
      plant_list &lt;- append(plant_list, df$plant)
    } else {}
  }
  </code></pre>
  <p>but this gives me an error. What is a good solution ?(preferably with dplyr, but anyway would be great!)</p>