arrayIndex              package:R.utils              R Documentation

_C_o_n_v_e_r_t_s _v_e_c_t_o_r _i_n_d_i_c_e_s _t_o _a_r_r_a_y _i_n_d_i_c_e_s

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

     Converts vector indices to array indices assuming last array
     dimension to "move fastest", e.g. matrices are stored column by
     column.

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

     ## Default S3 method:
     arrayIndex(i, dim, ...)

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

       i: A 'vector' of vector indices to be converted to array
          indices.

     dim: A non-empty 'numeric' 'vector' specifying the dimension of
          the array.

     ...: Not used.

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

     Returns a 'numeric' 'matrix' of 'length(i)' rows and 'length(dim)'
     columns.

_R_e_f_e_r_e_n_c_e_s:

     [1] H. Bengtsson, _Bayesian Networks - a self-contained
     introduction with implementation remarks_, Master's Thesis in
     Computer Science, Mathematical Statistics, Lund Institute of
     Technology, 1999.

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

     'which'() with argument 'arr.ind=TRUE'.

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

     # Single index
     print(arrayIndex(21, dim=c(4,3,3)))

     # Multiple indices
     print(arrayIndex(20:23, dim=c(4,3,3)))

     # Whole array
     x <- array(1:30, dim=c(5,6))
     print(arrayIndex(1:length(x), dim=dim(x)))

     # Find (row,column) of maximum value
     m <- diag(4-abs(-4:4))
     print(arrayIndex(which.max(m), dim=dim(m)))

