title: Another length error using dplyr mutate() and if_else()
body: <p>I have another problem similar to by previous question <a href="https://stackoverflow.com/questions/60581833/dplyr-error-with-mutate-when-attempting-to-change-variable-value-based-on-if-e">here</a>. As it is not exactly the same I have posted it as a new question.</p>
  
  <p>I am attempting to add a vector as a new column to a tbl, but my vector is shorter than the number of rows, therefore I am using <code>if_else()</code> to specify a condition. Here is a reprex and my attempted solution:</p>
  
  <pre><code>library(dplyr)
  library(magrittr)
  
  data &lt;- data.frame(
    ID = c("a100", "b100", "c100", "d100", "e100", "f100"),
    certainty = c("confirmed", "likely", "unsure", "likely", "unsure", "confirmed")
  )
  
  data %&lt;&gt;% as_tibble()
  
  add &lt;- c(1, 2)
  
  data %&lt;&gt;%
    mutate(new_var =
             if_else(certainty == "likely", add, NA_real_))
  </code></pre>
  
  <p>This currently gives me the error <code>Error: true must be length 6 (length of condition) or one, not 2</code>, but as far as I can understand my condition is of length 2 since <code>sum(data$certainty == "likely")</code> returns <code>[1] 2</code>.</p>
  
  <p>The result should look like this:</p>
  
  <pre><code>  ID    certainty new_var
    &lt;fct&gt; &lt;fct&gt;       &lt;dbl&gt;
  1 a100  confirmed      NA
  2 b100  likely          1
  3 c100  unsure         NA
  4 d100  likely          2
  5 e100  unsure         NA
  6 f100  confirmed      NA
  </code></pre>
  
  <p>What am I missing? Thanks again and sorry if this is a noob question, but I'm still trying to get to grips with the tidyverse!</p>