title: Using a value of column to get an element of a separate list (in a mutate() call)
body: <p>I am trying to use values from two columns in a row to essentially do a lookup within a set in a separate list. </p>
  
  <p>A code snippet is below:</p>
  
  <pre><code>library(tidyverse)
  
  # Sample days and hour of day
  df_hours &lt;- tibble(
    dow  = as.integer(c(rep(1, 5), rep(2, 5))), 
    hour = as.integer(rep(c(0:4), 2)), 
  )
  # Sample hours open. One set per day of week
  open_hrs &lt;- list(c(01:03), c(03:04))
  
  # Show before
  df_hours
  </code></pre>
  
  <p>The data:</p>
  
  <pre><code># A tibble: 10 x 2
       dow  hour
  &lt;int&gt; &lt;int&gt;
  1     1     0
  2     1     1
  3     1     2
  4     1     3
  5     1     4
  6     2     0
  7     2     1
  8     2     2
  9     2     3
  10     2     4
  </code></pre>
  
  <p>Then attempting the lookup:</p>
  
  <pre><code># Lookup the hour in the dow open_hrs set and add the result for the row
  df_hours &lt;- df_hours %&gt;% 
    mutate(
      open = ifelse(hour %in% unlist(open_hrs[ dow ]), 1, 0)
    )
  
  # Show result
  df_hours
  </code></pre>
  
  <p>The result:</p>
  
  <pre><code># A tibble: 10 x 3
       dow  hour  open
  &lt;int&gt; &lt;int&gt; &lt;dbl&gt;
  1     1     0     0
  2     1     1     1
  3     1     2     1
  4     1     3     1
  5     1     4     1
  6     2     0     0
  7     2     1     1
  8     2     2     1
  9     2     3     1
  10     2     4     1
  </code></pre>
  
  <p>This seems to have used a combination of all values in "open_hrs".
  I believe the issues is that "dow" is not being passed is as the value for that "row".</p>
  
  <p>What I'm seeking as a result is:</p>
  
  <pre><code>     dow  hour  open
  &lt;int&gt; &lt;int&gt; &lt;dbl&gt;
  1     1     0     0
  2     1     1     1
  3     1     2     1
  4     1     3     1
  5     1     4     0
  6     2     0     0
  7     2     1     0
  8     2     2     0
  9     2     3     1
  10     2     4     1
  </code></pre>
  
  <p>I've also tried to use sapply() also but without success.</p>
  
  <p>Thanks in advance.</p>