title: How to Create a function that will return the sum of 2 integers?
body: <p>I've encountered a simple question but failed to write the code. Grateful if you can help me.</p>
  
  <p>The question: Create a function that will return the sum of 2 integers.</p>
  
  <p>My code:</p>
  
  <pre><code>q1 &lt;- function(a, b) {
    if (a == as.integer(a)) {
      if (b == as.integer(b)) {
        result1 &lt;- a + b
      }
    }
  } else {
    result1 &lt;- NA
    result1
  }
  </code></pre>
  
  <p>q1(3,6) - suppose it returns 9</p>
  
  <p>q1(3.1,6) - suppose it returns NA</p>
  
  <p>BTW, why can I not write the syntax in this way?
  <code>if(is.integer(a) = TRUE){</code></p>