col                   package:base                   R Documentation

_C_o_l_u_m_n _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 column number in a
     matrix-like object, or a factor of column labels.

_U_s_a_g_e:

     col(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 column 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 'j' (or the 'j'-th column
     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:

     'row' to get rows.

_E_x_a_m_p_l_e_s:

     # extract an off-diagonal of a matrix
     ma <- matrix(1:12, 3, 4)
     ma[row(ma) == col(ma) + 1]

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

