title: sum up a numeric column with a sliding window defined by values in another column
body: <p>I am now facing a problem of summing up a numeric column with a sliding window defined by values in another column.</p>
  
  <p>(1) My data are tab-delimited, with two numeric columns:</p>
  
  <pre><code>1000 12
  2000 10
  3000 9
  5000 3
  9000 5
  10000 90
  30000 20
  31000 32
  39000 33
  40000 28
  </code></pre>
  
  <p>(2) I want to sum up 2nd column with a window defined by 1st column, window size is (1st column + 3000). This means I need to add the 3rd column (3rd column = sum(all values of the 2nd columns in rows of 1st column to 1st cloumn+3000)). </p>
  
  <p>It looks like this:</p>
  
  <pre><code>1000 12 12+10+9
  2000 10 10+9+3
  3000 9 9
  5000 3 3
  9000 5 5+90
  10000 90 90
  30000 20 20+32
  31000 32 32
  39000 33 33
  40000 28
  </code></pre>
  
  <p>(3) I am new for programming. I tried awk, but I am failed.</p>
  
  <h1>I do not know how to control the window for the 1st column</h1>
  
  <p>awk '(i = 1; i &lt;= NR; i++) { sum[i]+=$2 } END {print $1,$2,sum}' mydata</p>
  
  <p>Could anyone give me any advice/directions on the problem? Thanks in advance.</p>
  
  <p>Best,</p>