title: IF/THEN/ELSE in R
body: <p>everyone.</p>
  
  <p>Hopefully an easy syntax question. I'm trying to create a new variable in a table in R which would say "1" if my patient was in the age range I was looking at, or "0" for no. The age range I'm interested is between 2-155. The code is running without any errors, but it is not working. When I look in my table, the new variable will say 1 even though the age4 is 158 Here is what I have:</p>
  
  <pre><code>table$newvar &lt;- if (table$age4&gt;=2 &amp;&amp; table$age4 &lt;=155) {table$newvar=1} else {table$newvar=0}
  </code></pre>
  
  <p>Any help is appreciated! Thanks in advance!</p>