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.