title: Function that i want to substract R
body: <p>I have this formula in R, i want to be able to apply it to a different number of value without rewriting it again. e.g: 6 price comparisons instead of 4. How can i do that?
  i have been doing is this way, but when i want to compare to different lags and leads, I have to rewrite it</p>
  <pre><code>a&lt;- for (i in price [sP+1]:length(price)){
        if (price[i] &lt; price[i-1] &amp; price[i] &lt; price[i-2] &amp; 
            price[i] &lt; price[i-3] &amp; price[i] &lt; price[i-4] &amp;
            price[i] &lt; price[i+1] &amp; price[i] &lt; price[i+2] &amp;
            price[i] &lt; price[i+3] &amp; price[i] &lt; price[i+4]) 
      }
  </code></pre>