title: Integrating step function in R
body: <p>I have 2 functions whose integrals sum up to 1:</p>
  
  <pre><code>&gt; body &lt;- function(x) {dlnorm(x, meanlog=5.141287, sdlog=1.563058)}
  &gt; tail &lt;- function(x) {16.11505*x**-1.752366}
  &gt; integrate(body, 1, 100)$value + integrate(tail, 100, 5002)$value
  [1] 1
  </code></pre>
  
  <p>However, when I define a step function from the 2 functions, the integral of the step function doesn't equal to 1:</p>
  
  <pre><code>&gt; double_pareto &lt;- function(x) {if (x &lt; 100) body(x) else tail(x)}
  &gt; integrate(double_pareto, 1, 5002)
  1.074265 with absolute error &lt; 3.6e-05
  There were 13 warnings (use warnings() to see them)
  &gt; warnings()
  Warning messages:
  1: In if (x &lt; 100) body(x) else tail(x) :
    the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>Why is that? what is the proper way to integrating a step function in R?</p>