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

