This comes as an application to this question:
http://stackoverflow.com/questions/5896648/sum-object-in-a-column-between-an-interval-defined-by-another-column/5897695#comment23166107_5897695

What I would like to know is how to adjust the answer if I want to sum the
values in B, for ((A[i+1]-A[i]==0) or (A[i+1]-A[i]==1) or (A[i]-A[i-1]==0)
or (A[i]-A[i-1]==1)) where i is the row index, so basically sum B rows for
A-s that have the same value +/- 1, but not sum the same row twice?
I tried building a loop function but I get stuck when using row indices
with data frames. So if I have the next data frame:

 df
       A B
 [1,]  1 4
 [2,]  1 3
 [3,]  3 5
 [4,]  3 7
 [5,]  4 3
 [6,]  5 2



The result I would obtain(considering that when I have ), would be:

 df
       A B
 [1,]  1 7
 [2,]  3 15
 [3,]  5 2


- Nanami

	[[alternative HTML version deleted]]

