controlledSubsetting       package:arrayMagic       R Documentation

_S_u_b_s_e_t_t_i_n_g _o_f _A_r_r_a_y_s

_D_e_s_c_r_i_p_t_i_o_n:

     Finer control on the drop argument as in []

_U_s_a_g_e:

     controlledSubsetting(a, ranges, drop)

_A_r_g_u_m_e_n_t_s:

       a: array; required; default: missing.

  ranges: list of vectors; list length must match dimensionality of a;
          each element of the numeric vector specifies the subset of
          the corresponding dimension of a; if is.na(element) the whole
          corresponding dimension is kept; required; default: missing.

    drop: optional; specifies each dimension of array a which will be
          dropped, the corresponding subset must specify exact one
          element; if missing all such subsets are dropped; default:
          missing.

_D_e_t_a_i_l_s:

_V_a_l_u_e:

     subsetted array

_A_u_t_h_o_r(_s):

     Andreas Buness <a.buness@dkfz.de>

_S_e_e _A_l_s_o:

     'controlledApply'

_E_x_a_m_p_l_e_s:

                 a <- array(1:400, dim=c(2,3,5,6))
                 r <- controlledSubsetting(a=a, ranges=list(1,2,3,2), drop=2)
                 stopifnot(length(dim(r)) == 3 )
                 stopifnot(r == a[1,2,3,2])
                 r <- controlledSubsetting(a=a, ranges=list(2,1:2,2,2:3), drop=3)
                 stopifnot( all(r[1,,,drop=TRUE] == a[2,1:2,2,2:3]) )
                 r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=3)
                 stopifnot( all(r[,,1,drop=TRUE] == a[1:2,1:2,2,3]) )
                 r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=c(3,4))
                 stopifnot( all(r == a[1:2,1:2,2,3]) )
                 r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,1:5,3), drop=c(4))
                 stopifnot( all(r == a[1:2,1:2,1:5,3]) )
                 r <- controlledSubsetting(a=a, ranges=list(NA,NA,1:5,3), drop=c(4))
                 stopifnot( all(r == a[,,1:5,3]) )

             

