allsums                package:magic                R Documentation

_R_o_w, _c_o_l_u_m_n, _a_n_d _t_w_o _d_i_a_g_o_n_a_l _s_u_m_s _o_f _a_r_r_a_y_s

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

     Returns all rowsums, all columnsums, and all (broken) diagonal
     sums of a putative magic square.

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

     allsums(m,FUN=sum)

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

       m: The square to be tested

     FUN: Function, defaulting to 'sum', to be applied to the square
          rowwise, columnwise, and diagonalwise

_V_a_l_u_e:

     Returns a list of four elements.  In the following, "sums" means
     "the result of applying FUN()". 

 rowsums: All n row sums

 colsums: All n column sums

  majors: All n broken major diagonals (northwest-southeast). First
          element is the long (unbroken) major diagonal, tested by
          'is.magic()'

  minors: All n broken minor diagonals (northeast-southwest). First
          element is the long (unbroken) minor diagonal.

_N_o_t_e:

     If 'FUN()' returns a vector, then the columns of the four elements
     are the result of applying 'FUN()'.  See third example below.

     Used by 'is.magic()' et seq.

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

     Robin K. S. Hankin

_S_e_e _A_l_s_o:

     'is.magic',\ 'is.semimagic',\ 'is.panmagic'

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

     allsums(magic(7))
     allsums(magic(7),FUN=max)
     allsums(magic(7),FUN=function(x){x[1:2]})
       # shows how the minor diagonals are ordered: first [1,n] to [n,1] then
       # [1,n+1] to [n,2] etc.

     allsums(magic.prime(7),sort)
       # beware! compare apply(magic(7),1,sort) with apply(magic(7),2,sort)

