title: tagging windows around events within data.frame
body: <p>I have a data.frame with a factor identifying events</p>
  
  <blockquote>
    <p><code>year event
    1    0
    2    0
    3    0
    4    0
    5    0
    6    0
    7    0
    8    0
    9    1
    10   0
    11   0
    12   0
    13   0
    14   0
    15   0
    16   0
    17   1 
    18   0
    19   0
    20   0</code></p>
  </blockquote>
  
  <p>And I would need a counter-type identifying a given window around the events. The result should look like this (for a window that is, for example, 3 periods around the event):</p>
  
  <blockquote>
    <p><code>year event window
    1    0<br>
    2    0<br>
    3    0<br>
    4    0<br>
    5    0<br>
    6    0      -3
    7    0      -2
    8    0      -1
    9    1      0
    10   0      1
    11   0      2
    12   0      3
    13   0<br>
    14   0      -3
    15   0      -2
    16   0      -1
    17   1      0
    18   0      1
    19   0      2
    20   0      3</code></p>
  </blockquote>
  
  <p>Any guidance on how to implement this within a function would be appreciated. You can copy the data. frame, pasting the block above in "..." here:</p>
  
  <p><code>dt &lt;- read.table( text="...", , header = TRUE )</code></p>