title: Compute Rolling Rank of Xts Column
body: <p>I am an r beginner and I have an xts object with 1 column and 10000 rows, data does contain some NA's.  I am trying to find the rank of each value within the next 4 values in the same column.  For example if I have these values in col 1:</p>
  
  <pre><code>01/02/2018  25
  12/29/2017  16
  12/28/2017  22
  12/27/2017  6
  12/26/2017  17
  12/21/2017  11
  </code></pre>
  
  <p>I want this result:</p>
  
  <pre><code>01/02/2018  1   (25 is rank 1 of 25,16,22,6)
  12/29/2017  3   (16 is rank 3 of 16,22,6,17)
  12/28/2017  1   (22 is rank 1 of 22,6,17,11)
  </code></pre>
  
  <p>I have tried using rank function multiple different ways including:</p>
  
  <pre><code>apply(xts, 2, rank)
  </code></pre>
  
  <p>This ranks each value within the entire xts as opposed to ranking each value  within the preceding 4 values.  I can't seem to figure this out.  Any help would be greatly appreciated.</p>