row                   package:base                   R Documentation

_R_o_w _I_n_d_e_x_e_s

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

     Returns a matrix of integers indicating their row number in the
     matrix.

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

     row(x, as.factor = FALSE)

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

       x: a matrix.

as.factor: a logical value indicating whether the value should be
          returned as a factor rather than as numeric.

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

     An integer matrix with the same dimensions as 'x' and whose
     'ij'-th element is equal to 'i'.

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

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

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

     'col' to get columns.

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

     x <- matrix(1:12, 3, 4)
     # extract the diagonal of a matrix
     dx <- x[row(x) == col(x)]
     dx

     # create an identity 5-by-5 matrix
     x <- matrix(0, nr = 5, nc = 5)
     x[row(x) == col(x)] <- 1
     x

