title: How to define a piecewise function in R
body: <p>I want to define a piecewise function using R, however, my R code goes wrong. Any suggestion is welcome.</p>
  
  <pre><code>x&lt;-seq(-5, 5, by=0.01)
    for (x in -5:5){
    if (-0.326 &lt; x &lt; 0.652) fx&lt;- 0.632
    else if (-1.793&lt;x&lt;-1.304) fx&lt;- 0.454  
    else if (1.630&lt;x&lt;2.119) fx&lt;-0.227  
    else fx&lt;- 0 }
  </code></pre>