title: R error: if else statement in a loop, unexpected "}"
body: <p>I was trying to run these code, and got stuck..</p>
  
  <pre><code>a&lt;-data.frame(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
  n&lt;-1
  empty &lt;- data.frame(stringsAsFactors=F)
  while (n&lt;=5) {
      if (sum((a[,2*n+3]), (a[,2*n+4])) == 13) {
          empty &lt;-data.frame(cbind(empty, 3), n&lt;-n+1
      } else {
          empty &lt;-data.frame(cbind(empty, 2), n&lt;-n+1
      }
  }
  </code></pre>
  
  <p>These are what I got:</p>
  
  <pre><code>&gt; a&lt;-data.frame(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
  &gt; n&lt;-1
  &gt; empty &lt;- data.frame(stringsAsFactors=F)
  &gt; while (n&lt;=5) {
  +     if (sum((a[,2*n+3]), (a[,2*n+4])) == 13) {
  +         empty &lt;-data.frame(cbind(empty, 3), n&lt;-n+1
  +     } else {
  Error: unexpected '}' in:
  "        empty &lt;-data.frame(cbind(empty, 3), n&lt;-n+1
      }"
  &gt;         empty &lt;-data.frame(cbind(empty, 2), n&lt;-n+1
  +     }
  Error: unexpected '}' in:
  "        empty &lt;-data.frame(cbind(empty, 2), n&lt;-n+1
      }"
  &gt; }
  Error: unexpected '}' in "}"
  </code></pre>
  
  <p>I've tried many combinations of taking away "{}" or even write the code into the same line with or without these "{}", none of them work. What's wrong with my code?</p>