row/colnames package:base R Documentation _R_o_w _a_n_d _C_o_l_u_m_n _N_a_m_e_s _D_e_s_c_r_i_p_t_i_o_n: Retrieve or set the row or column names of a matrix-like object. _U_s_a_g_e: rownames(x, do.NULL = TRUE, prefix = "row") rownames(x) <- value colnames(x, do.NULL = TRUE, prefix = "col") colnames(x) <- value _A_r_g_u_m_e_n_t_s: x: a matrix-like R object, with at least two dimensions for 'colnames'. do.NULL: logical. Should this create names if they are 'NULL'? prefix: for created names. value: a valid value for that component of 'dimnames(x)'. For a matrix or array this is either 'NULL' or a character vector of non-zero length equal to the appropriate dimension. _D_e_t_a_i_l_s: The extractor functions try to do something sensible for any matrix-like object 'x'. If the object has 'dimnames' the first component is used as the row names, and the second component (if any) is used for the column names. For a data frame, 'rownames' and 'colnames' eventually call 'row.names' and 'names' respectively, but the latter are preferred. If 'do.NULL' is 'FALSE', a character vector (of length 'NROW(x)' or 'NCOL(x)') is returned in any case, prepending 'prefix' to simple numbers, if there are no dimnames or the corresponding component of the dimnames is 'NULL'. The replacement methods for arrays/matrices coerce vector and factor values of 'value' to character, but do not dispatch methods for 'as.character'. For a data frame, 'value' for 'rownames' should be a character vector of non-duplicated and non-missing names (this is enforced), and for 'colnames' a character vector of (preferably) unique syntactically-valid names. In both cases, 'value' will be coerced by 'as.character', and setting 'colnames' will convert the row names to character. _S_e_e _A_l_s_o: 'dimnames', 'case.names', 'variable.names'. _E_x_a_m_p_l_e_s: m0 <- matrix(NA, 4, 0) rownames(m0) m2 <- cbind(1,1:4) colnames(m2, do.NULL = FALSE) colnames(m2) <- c("x","Y") rownames(m2) <- rownames(m2, do.NULL = FALSE, prefix = "Obs.") m2