nn.cumsum {smerc} | R Documentation |
nn.cumsum
computes the cumulative sum of y
for the sequences of indices in each element of the list
contained in nn
.
nn.cumsum(nn, y, simplify = TRUE)
nn |
A list of nearest neighbors in the format
produced by |
y |
A numeric vector of values to be summed over. |
simplify |
A logical value indicating whether the
results should be simplified to a numeric vector. The
default is |
A vector or list, depending on the value of
simplify
.
# show nn.cumsum example for a circular scan setting data(nydf) coords = with(nydf, cbind(longitude, latitude)) cases = floor(nydf$cases) d = sp::spDists(coords, longlat = TRUE) # compute circular nearest neigbhors nn = nnpop(d, pop = nydf$pop, ubpop = 0.1) # compute cumulative sums over all nn cnn = nn.cumsum(nn, cases) # compute cumulative sums over just the first set of nn cnn1 = cumsum(cases[nn[[1]]]) # check equality all.equal(cnn1, cnn[seq_along(cnn1)])