title: Using case_when with multiple vectors
body: <p>I am trying to use <code>case_when</code> to modify/mutate a column based on two separate inputs. One that used to create the LHS logical and the respective input value on the RHS. An example is provided below.</p>
  
  <pre><code>library(dplyr)
  library(purrr)
  library(tibble)
  
  df &lt;- tibble(var = paste0(rep("var", 10), 1:10),
                   label = c("label1", "label2", rep(NA, 7), "label10"))
  
  match_var &lt;- paste0(rep("var", 7), 3:9)
  new_labels &lt;- paste0(rep("add_this_label", 7), 3:9)
  
  df %&gt;% 
    mutate(test = map2(match_var , new_labels,
                       ~case_when(
                         var == .x ~ .y,
                         TRUE ~ label
                       )
    ))
  </code></pre>
  
  <p>I think the issue is that within <code>case_when</code> everything is evaluated as expression but I'm not completely sure. One can manually type out all 7 lines within <code>case_when</code> but my application requires me to accomplish this when the vectors <code>match_vars</code> and <code>new_labels</code> are very long - making manual typing of <code>case_when</code> infeasible.</p>
  
  <pre><code>df %&gt;% 
    mutate(label = case_when(
      var == match_var[1] ~ new_labels[1],
      var == match_var[2] ~ new_labels[2],
      var == match_var[3] ~ new_labels[3],
      var == match_var[4] ~ new_labels[4],
      var == match_var[5] ~ new_labels[5],
      var == match_var[6] ~ new_labels[6],
      var == match_var[7] ~ new_labels[7],
      TRUE ~ label
    ))
  </code></pre>
  
  <p><strong>EDIT</strong>: the desired result can be accomplished using a <code>for</code> loop but now I want to know if is this possible using <code>case_when</code> and <code>map2_*</code> function?</p>
  
  <pre><code>for (i in seq_along(match_var)) {
    df$label &lt;- ifelse(df$var == match_var[i], new_labels[i], df$label)
  }
  </code></pre>