title: Avoiding type conflicts with dplyr::case_when
body: <p>I am trying to use <code>dplyr::case_when</code> within <code>dplyr::mutate</code> to create a new variable where I set some values to missing and recode other values simultaneously.</p>
  
  <p>However, if I try to set values to <code>NA</code>, I get an error saying that we cannot create the variable <code>new</code> because <code>NA</code>s are logical:</p>
  
  <blockquote>
    <p>Error in mutate_impl(.data, dots) :<br>
      Evaluation error: must be type double, not logical.</p>
  </blockquote>
  
  <p>Is there a way to set values to <code>NA</code> in a non-logical vector in a data frame using this?</p>
  
  <pre><code>library(dplyr)    
  
  # Create data
  df &lt;- data.frame(old = 1:3)
  
  # Create new variable
  df &lt;- df %&gt;% dplyr::mutate(new = dplyr::case_when(old == 1 ~ 5,
                                                    old == 2 ~ NA,
                                                    TRUE ~ old))
  
  # Desired output
  c(5, NA, 3)
  </code></pre>