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 a
     matrix-like object, or a factor indicating the row labels.

_U_s_a_g_e:

     row(x, as.factor = FALSE)

_A_r_g_u_m_e_n_t_s:

       x: a matrix-like object, that is one with a two-dimensional
          'dim'.

as.factor: a logical value indicating whether the value should be
          returned as a factor of row labels (created if necessary)
          rather than as numbers.

_V_a_l_u_e:

     An integer (or factor) matrix with the same dimensions as 'x' and
     whose 'ij'-th element is equal to 'i' (or the 'i'-th row label).

_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, nrow = 5, ncol = 5)
     x[row(x) == col(x)] <- 1
     x

