title: handling NA in if_else in r
body: <p>I have the following dataset with three columns containing dates.</p>
  
  <pre><code>library(dplyr)
  
  set.seed(45)
  
  df1 &lt;- data.frame(hire_date = sample(seq(as.Date('1999/01/01'),    as.Date('2000/01/01'), by="week"), 10),
                t1 = sample(seq(as.Date('2000/01/01'), as.Date('2001/01/01'), by="week"), 10),
                t2 = sample(seq(as.Date('2000/01/01'), as.Date('2001/01/01'), by="day"), 10))
  
  #this value is actually unknown
  df1[10,2] &lt;- NA
  
      hire_date         t1         t2
  1  1999-08-20 2000-05-13 2000-02-17   
  2  1999-04-23 2000-11-11 2000-04-27   
  3  1999-03-26 2000-04-15 2000-08-01   
  4  1999-05-07 2000-06-03 2000-08-29   
  5  1999-04-30 2000-05-27 2000-11-19   
  6  1999-04-09 2000-12-30 2000-01-26   
  7  1999-03-12 2000-12-23 2000-12-07  
  8  1999-06-25 2000-02-12 2000-09-26  
  9  1999-02-26 2000-05-06 2000-08-23 
  10 1999-01-01       &lt;NA&gt; 2000-03-18 
  </code></pre>
  
  <p>I'd like to perform an if else statement such that df1$com is 1 if the difference between t1 OR t2 and hire_date is between [395,500]</p>
  
  <p>The following if_else statement almost gets me there, but the NA mucks it up. Any ideas?</p>
  
  <pre><code>df1$com &lt;- if_else((df1$t1 - df1$hire_date) &gt;= 395 &amp;
                 (df1$t1 - df1$hire_date) &lt;= 500, 1,
         if_else((df1$t2 - df1$hire_date) &gt;= 395 &amp;
                  (df1$t2 - df1$hire_date) &lt;= 500, 1, 0))
  </code></pre>