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

