title: spatial data / compute metrics on neighbors in R
body: <p>I have the 2D spatial data in the form (xBin, yBin, value).
  e.g.:</p>
  
  <pre><code>DT = data.table(x=c(rep(1,3),rep(2,3),rep(3,3)),y=rep(c(1,2,3),3),value=100*c(1:9))
  </code></pre>
  
  <p>For each bin I want to compute the sum of variable "value" over all neighboring bins.
  A bin is considered a neighbor if both of its indices - x and y are within one unit from the current bin</p>
  
  <p>e.g. for x=2, y=2, I want to compute</p>
  
  <pre><code>valueNeighbors(x=2,y=2) = value(x=1,y=1)+value(1,2)+value(1,3)
  +value(2,1)+value(2,3)
  +value(3,1)+value(3,2)+value(3,3)
  </code></pre>
  
  <p>My real data has ~1,000^2 bins, how can I do this efficiently?</p>