| subsums {magic} | R Documentation |
Returns the sums of submatrices of an array; multidimensional moving window averaging
subsums(a,p,FUN="sum",wrap=TRUE, pad.value=0)
a |
Array to be analysed |
p |
Argument specifying the subarrays to be summed. If a vector,
it is assumed to be of length d=length(dim(a)), and is
interpreted to be
the dimensions of the subarrays, with
the size of the window's n-th dimension being
a[n].
If not a vector, is assumed to be a matrix with d columns, each
row representing the coordinates of the elements to be summed. See
examples.
|
FUN |
Function to be applied over the elements of the moving
window. Default value of sum gives the sum as used in
is.2x2.correct(); other choices might be mean,
prod, or max.
If sum="", return the array of dimension
c(dim(a),prod(p)) where each hyperplane is a shifted version
of a. |
wrap |
Boolean, with default value of TRUE meaning to view
array a as a n-dimensional torus. Thus, if
x=subsums(a,p,wrap=TRUE), and if dim(a)=c(a_1,...,a_d)
then x[a_1,...,a_d] is the sum of all corner elements of
a.
If FALSE, do not wrap a and return an array of
dimension dim(a)+p-1. |
pad.value |
If wrap is TRUE, pad.value is
the value used to pad the array with. Use a “neutral” value here;
for example, if FUN=sum, then use 0; if max, use
-Inf. |
The offset is specified so that allsums(a,v)[1,1,...,1]=
sum(a[1:v[1],1:v[2],...,1:v[n]]), where n=length(dim(a)).
Function subsums() is used in is.2x2.correct() and
is.diagonally.correct().
Robin K. S. Hankin
data(Ollerenshaw) subsums(Ollerenshaw,c(2,2)) subsums(Ollerenshaw[,1:10],c(2,2)) subsums(Ollerenshaw, matrix(c(0,6),2,2))