title: Ignore NA's in sapply function
body: <p>I am using R and have searched around for an answer but while I have seen similar questions, it has not worked for my specific problem. </p>
  
  <p>In my data set I am trying to use the <code>NA</code>'s as placeholders because I am going to return to them once I get part of my analysis done so therefore, I would like to be able to do all my calculations as if the <code>NA</code>'s weren't really there. </p>
  
  <p>Here's my issue with an example data table</p>
  
  <pre><code>ROCA = c(1,3,6,2,1,NA,2,NA,1,NA,4,NA)
  ROCA &lt;- data.frame (ROCA=ROCA)       # converting it just because that is the format of my original data
  
  #Now my function
  exceedes &lt;- function (L=NULL, R=NULL, na.rm = T)
   {
      if (is.null(L) | is.null(R)) {
          print ("mycols: invalid L,R.")
          return (NULL)               
      }
      test &lt;-(mean(L, na.rm=TRUE)-R*sd(L,na.rm=TRUE))
    test1 &lt;- sapply(L,function(x) if((x)&gt; test){1} else {0})
    return (test1)
  }
  L=ROCA[,1]
  R=.5
  ROCA$newcolumn &lt;- exceedes(L,R)
  names(ROCA)[names(ROCA)=="newcolumn"]="Exceedes1"
  </code></pre>
  
  <p>I am getting the error: </p>
  
  <pre><code>Error in if ((x) &gt; test) { : missing value where TRUE/FALSE needed 
  </code></pre>
  
  <p>As you guys know, it is something wrong with the sapply function. Any ideas on how to ignore those <code>NA</code>'s? I would try <code>na.omit</code> if I could get it to insert all the <code>NA</code>'s right where they were before, but I am not sure how to do that.</p>