title: How to include NA in ifelse?
body: <p>I am trying to create a column <code>ID</code> based on logical statements for values of other columns. For example, in the following dataframe</p>
  
  <pre><code>test &lt;- structure(list(time = c(10L, 20L, NA, 30L), type = structure(c(1L, 
  2L, 3L, NA), .Label = c("A", "B", "C"), class = "factor"), ID = c(NA, 
  "1", NA, NA)), .Names = c("time", "type", "ID"), row.names = c(NA, 
  -4L), class = "data.frame")
  </code></pre>
  
  <p>which looks like</p>
  
  <pre><code>    time    type
  1   10      A
  2   20      B
  3   NA      C
  4   30      NA
  </code></pre>
  
  <p>I want to make a new column <code>ID</code> containing a value of 1 for all <code>time</code> that are not <code>NA</code> and all <code>type</code> that are not <code>A</code>. I am using the following code for this:</p>
  
  <pre><code>test$ID &lt;- ifelse(is.na(test$time) | test$type == "A", NA, "1")
  </code></pre>
  
  <p>This gives the result as </p>
  
  <pre><code>    time    type    ID
  1   10      A       NA
  2   20      B       1
  3   NA      C       NA
  4   30      NA      NA
  </code></pre>
  
  <p>However, this code ignores the <code>NA</code> in column <code>type</code>, resulting in a value of <code>NA</code> in column <code>ID</code>. I need this to be a value of 1, so my needed solution should give:</p>
  
  <pre><code>    time    type    ID
  1   10      A       NA
  2   20      B       1
  3   NA      C       NA
  4   30      NA      1
  </code></pre>
  
  <p>Can anyone tell me how I might do this? I could get this to work with my existing code if I could somehow change the result of <code>is.na(test$type)</code> to return <code>FALSE</code> instead of <code>TRUE</code>, but I'm not sure how to do that. Or, maybe the structure of my existing code needs to be entirely changed?  I appreciate any help!</p>