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]) )

             

