subsums | R Documentation |
Returns the sums of submatrices of an array; multidimensional moving window averaging
subsums(a,p,func="sum",wrap=TRUE, pad=0)
a |
Array to be analysed |
p |
Argument specifying the subarrays to be summed. If a vector
of length greater than one,
it is assumed to be of length If not a vector, is assumed to be a matrix with |
func |
Function to be applied over the elements of the moving
window. Default value of If |
wrap |
Boolean, with default value of If |
pad |
If |
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)) # effectively, is.bree.correct() # multidimensional example. a <- array(1,c(3,4,2)) subsums(a,2) # note that p=2 is equivalent to p=c(2,2,2); # all elements should be identical subsums(a,2,wrap=FALSE) #note "middle" elements > "outer" elements #Example of nondefault function: x <- matrix(1:42,6,7) subsums(x,2,func="max",pad=Inf,wrap=TRUE) subsums(x,2,func="max",pad=Inf,wrap=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.