subsums                package:magic                R Documentation

_S_u_m_s _o_f _s_u_b_m_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Returns the sums of submatrices of an array; multidimensional
     moving window averaging

_U_s_a_g_e:

     subsums(a,p,FUN="sum",wrap=TRUE, pad.value=0)

_A_r_g_u_m_e_n_t_s:

       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.

_D_e_t_a_i_l_s:

     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()'.

_A_u_t_h_o_r(_s):

     Robin K. S. Hankin

_E_x_a_m_p_l_e_s:

       data(Ollerenshaw)
       subsums(Ollerenshaw,c(2,2))
       subsums(Ollerenshaw[,1:10],c(2,2))
       subsums(Ollerenshaw, matrix(c(0,6),2,2))

