title: Loop for taking sum of rows based on proximity to other non-NA rows
body: <p>I have a dataset with 2 important columns, <code>Position</code> and <code>Count</code>. There are a total of 34,532 rows, but only 457 non-NA values in the <code>Count</code> column (every cell in <code>Position</code> column has a value). I need to write a loop to march down the rows, and if there are 2 rows in <code>Count</code> where there is only 1 <code>NA</code> row between them, sum the two values up and print only one row with the summed Count value and the Position value that corresponds to the larger Count value, thus making the three rows into one. For example:</p>
  
  <pre><code>Position Count
  15       15
  22       NA
  38       NA
  49        5
  55       NA
  61       17
  </code></pre>
  
  <p>would become</p>
  
  <pre><code>Position Count
  15        15
  22        NA
  38        NA
  61        22
  </code></pre>
  
  <p>After this step, I also need to write another script to march down the rows and look for rows with only two NA's between non-NA rows in Count. This would make the previous data become</p>
  
  <pre><code>Position Count
  61        37
  </code></pre>
  
  <p>Ideally I would like a loop that can be flexibly adjusted to the number of NA's in between adjacent non-NA values that can be freely changed. I would greatly appreciate any insight for this. </p>