rowMedians              package:Biobase              R Documentation

_C_a_l_c_u_l_a_t_e_s _t_h_e _m_e_d_i_a_n _f_o_r _e_a_c_h _r_o_w _i_n _a _m_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     Calculates the median for each row in a matrix.

_U_s_a_g_e:

     rowMedians(imat, na.rm=FALSE)

_A_r_g_u_m_e_n_t_s:

    imat: A 'numeric' 'matrix'.

   na.rm: If 'TRUE', 'NA's are excluded before calculating the medians,
          otherwise not.

     ...: Not use.

_V_a_l_u_e:

     Returns a 'double' 'vector' of length equal to number of rows in
     'x'.

_M_i_s_s_i_n_g _v_a_l_u_e_s:

     Missing values are excluded before calculating the medians.

_B_e_n_c_h_m_a_r_k_i_n_g:

     This implementation is optimized for speed and memory to
     calculate. As the example shows, this implementation is roughly
     3-10 times faster than using 'apply(x, MARGIN=1, FUN=medians)'. As
     the example might show, the 'rowQ()' does not (have to) handle
     missing values, and is therefore in some cases faster.

_A_u_t_h_o_r(_s):

     Henrik Bengtsson

_S_e_e _A_l_s_o:

     See 'rowMeans()' in 'colSums'().

_E_x_a_m_p_l_e_s:

     set.seed(1)
     x <- rnorm(n=234*543)
     x[sample(1:length(x), size=0.1*length(x))] <- NA
     dim(x) <- c(234,543)
     y1 <- rowMedians(x, na.rm=TRUE)
     y2 <- apply(x, MARGIN=1, FUN=median, na.rm=TRUE)
     stopifnot(all.equal(y1, y2))

     x <- cbind(x1=3, x2=c(4:1, 2:5))
     stopifnot(all.equal(rowMeans(x), rowMedians(x)))

