title: Multiple actions in IF ELSE statement
body: <p>A sample data frame looks like this:</p>
  
  <pre><code>df = data.frame(a=1:5, b=11:15)
  a  b
  1 11
  2 12
  3 13
  4 14
  5 15
  </code></pre>
  
  <p>How do I use if else statement to create new column c and d in the data frame?
  I want the output to look like this:</p>
  
  <pre><code>a b    c    d
  1 11 'yes'  22
  2 12 'yes'  24
  3 13 'yes'  26
  4 14 'no'   14
  5 15 'no    15
  </code></pre>
  
  <p>I've tried this according to (<a href="https://stackoverflow.com/questions/14100643/if-statement-with-multiple-actions-in-r">If statement with multiple actions in R</a>)!</p>
  
  <pre><code>for (i in nrow(df)){
    if (df$a[i] &lt;4) {
      df$c[i] = 'yes'; 
      df$d[i] = df$b[i]*2;
      df
    } else {
      df$c[i] = 'no'; 
      df$d[i] = df$b[i];
      df
    }
  }
  </code></pre>
  
  <p>But the output only provide the last row:</p>
  
  <pre><code> a  b   c  d
   1 11 &lt;NA&gt; NA
   2 12 &lt;NA&gt; NA
   3 13 &lt;NA&gt; NA
   4 14 &lt;NA&gt; NA
   5 15   no 15
  </code></pre>
  
  <p>Thanks in advance.</p>