title: How to create a new variable by comparing two other variables
body: <p>I have to create a variable named comorbidity based on the values present in two other variables and add it to the dataframe</p>
  
  <p>Now I have dataframe named diagnosis with variables as following</p>
  
  <pre><code>v1 &lt;- c(222,250,255,250.23)
  
  v2 &lt;- c(300,369,400,450)
  </code></pre>
  
  <p>now if v1 is not b/w 250-250.99 and v2 is not b/w 390-490 then value in new variable 0</p>
  
  <p>if v1 is b/w 250-250.99 and v2 is not b/w 390-490 then value in new variable 1 </p>
  
  <p>if v1 is not b/w 250-250.99 and v2 is b/w 390-490 then value in new variable 2</p>
  
  <p>if v1 is b/w 250-250.99 and v2 is b/w 390-490 then value in new variable 3</p>
  
  <p>I have tried <code>ifelse</code> and written a huge code but it doesn't give desirable answer
  part of my code below </p>
  
  <pre><code>diabetic_maindf$comorbidity_1_2 &lt;- 
  if_else((diagnosis$v1 == diagnosis$v2 ),0,
  
  if_else((diagnosis$v1 == 1 | diagnosis$v2 == 0),1, 
  
  if_else((diagnosis$v1 == 0 &amp; diagnosis$v2 == 1),1,
  
  </code></pre>
  
  <p>I want dataframe with 3rd variable as follows</p>
  
  <pre><code>v1 &lt;- c(222,250,255,250.23)
  
  v2 &lt;- c(300,369,400,450)
  
  new_var &lt;- c(0,1,2,3)
  </code></pre>
  
  <p>P.S: new to here don't know how to write in table form, sorry....</p>