title: R handling NA values while doing a comparison ifelse
body: <p>how can i tell > and &lt; operators to ignore NA values? Below code return NA on 1st row. I want it to return 0 as both conditions fail on that row </p>
  
  <pre><code>##sum by values
  df &lt;- data.frame(sex=c('M','F','M'),occupation=c('Student','Analyst','Analyst'),age=c(NA,6,9), marks=c(34,65,21))
  df
  #df$counting &lt;- ifelse(df$age &gt; 5 &amp; df$age &lt; 8, 1, 0)
  df$counting &lt;- ifelse(df$age &gt; 5 &amp; df$age &lt; 8, 1, 0)+ifelse(df$marks &gt; 60 &amp; df$marks &lt; 70, 1, 0)
  df
  </code></pre>