title: Create a new variable based on three variables in R
body: <p>I want to create a new variable called <code>N1</code> based on three existing variables (<code>resp</code>, <code>exp.1</code>, <code>exp.2</code>) in R.</p>
  <pre><code>df &lt;- data.frame(
                   resp = c(1, 2, 4, 3, 5, 7 ),
                   exp.1 = c(0, 0.24, 1, 1.5, 0, 0.4),
                   exp.2 = c(1, 1, 0, 0, 0.3, 0.2)
  )
  </code></pre>
  <pre><code>df   resp  exp.1   exp.2
  1   1      0        1
  2   2      0.24     1
  3   2      1        0
  4   4      1.5      0
  5   5      0        0.3
  6   7      0.4      0.2
   
  </code></pre>
  <p>I want to make a new variable <code>N1</code> like this:
  when <code>resp</code> &gt;4, extracting values from <code>exp.1</code>
  when <code>resp</code> &lt;4, extracting values from <code>exp.2</code>
  when <code>resp</code> == 4, making it missing values.</p>
  <p>The desired outcome is:</p>
  <pre><code>df   resp  exp.1   exp.2   N1
  1   1      0        1      1
  2   2      0.24     1      1
  3   4      1        0      NA
  4   3      1.5      0      0
  5   5      0        0.3    0
  6   7      0.4      0.2    0.4
   
  </code></pre>
  <p>I tried my best using <code>mutate()</code> or <code>car::recode()</code> but it does not work. Any clues?</p>