title: R code: how to generate variable based on multiple conditions from other variables
body: <p>I have a beginner R user:</p>
  
  <p>This is my dataset</p>
  
  <pre><code>factor1 &lt;- c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,8,9, 9, 10, 10)
  factor2 &lt;- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16,17, 18, 19, 20)
  factor3 &lt;- c("a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "d", "d", "d", "d", "d")
  factor4 &lt;- c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150,160,170, 180, 190, NA)
  dataset &lt;- data.frame(factor1, factor2, factor3, factor4) 
  </code></pre>
  
  <p>I created a new variable this way:</p>
  
  <pre><code>dataset$newvar &lt;-"NA"
  </code></pre>
  
  <p>How to do the following:</p>
  
  <p>I want newvar to take the value 1 if factor1>=5 and factor2&lt;19 and (factor3="b" or factor3="c") and factor4 is different from missing and newvar is equal to missing</p>
  
  <p>Ideally I want to specify different conditions, so some observations will be value 1, 2, 3 and 4 in the variable newvar dependent on the values of several other variables.</p>
  
  <p>This is very simple and intuitive in STATA and would like to know if there is a simple and intuitive way to do the same in R.</p>