ormat.POSIXct?package=base&version=3.6.2) ` ) and for
other classes such as ` format.octmode ` and ` format.dist ` .

` format.data.frame ` formats the data frame column by column, applying the
appropriate method of ` format ` for each column. Methods for columns are
often similar to ` as.character ` but offer more control. Matrix and data-
frame columns will be converted to separate columns in the result, and
character columns (normally all) will be given class ` " [ AsIs
](/link/AsIs?package=base&version=3.6.2) " ` .

` format.factor ` converts the factor to a character vector and then calls the
default method (and so ` justify ` applies).

` format.AsIs ` deals with columns of complicated objects that have been
extracted from a data frame. Character objects and (atomic) matrices are
passed to the default method (and so ` width ` does not apply). Otherwise it
calls ` [ toString ](/link/toString?package=base&version=3.6.2) ` to convert
the object to character (if a vector or list, element by element) and then
right-justifies the result.

Justification for character vectors (and objects converted to character
vectors by their methods) is done on display width (see ` [ nchar
](/link/nchar?package=base&version=3.6.2) ` ), taking double-width characters
and the rendering of special characters (as escape sequences, including
escaping backslash but not double quote: see ` [ print.default
](/link/print.default?package=base&version=3.6.2) ` ) into account. Thus the
width is as displayed by ` print(quote = FALSE) ` and not as displayed by ` [
cat ](/link/cat?package=base&version=3.6.2) ` . Character strings are padded
with blanks to the display width of the widest. (If ` na.encode = FALSE `
missing character strings are not included in the width computations and are
not encoded.)

Numeric vectors are encoded with the minimum number of decimal places needed
to display all the elements to at least the ` digits ` significant digits.
However, if all the elements then have trailing zeroes, the number of decimal
places is reduced until ` nsmall ` is reached or at least one element has a
non-zero final digit; see also the argument documentation for ` big.* ` , `
small.* ` etc, above. See the note in ` [ print.default
](/link/print.default?package=base&version=3.6.2) ` about ` digits >= 16 ` .

Raw vectors are converted to their 2-digit hexadecimal representation by ` [
as.character ](/link/as.character?package=base&version=3.6.2) ` .

` format.default(x) ` now provides a “minimal” string when ` [ isS4
](/link/isS4?package=base&version=3.6.2) (x) ` is true.

The internal code respects the option ` [ getOption
](/link/getOption?package=base&version=3.6.2) ("OutDec") ` for the ‘decimal
mark’, so if this is set to something other than ` "." ` then it takes
precedence over argument ` decimal.mark ` .

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ format.info ](/link/format.info?package=base&version=3.6.2) ` indicates
how an atomic vector would be formatted.

` [ formatC ](/link/formatC?package=base&version=3.6.2) ` , ` [ paste
](/link/paste?package=base&version=3.6.2) ` , ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` , ` [ sprintf
](/link/sprintf?package=base&version=3.6.2) ` , ` [ print
](/link/print?package=base&version=3.6.2) ` , ` [ prettyNum
](/link/prettyNum?package=base&version=3.6.2) ` , ` [ toString
](/link/toString?package=base&version=3.6.2) ` , ` [ encodeString
](/link/encodeString?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fformat&utm_source=r-docs&utm_medium=docs&utm_term=format&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    format(1:10)
    format(1:10, trim = TRUE)
    
    zz <- data.frame("(row names)"= c("aaaaa", "b"), check.names = FALSE)
    format(zz)
    format(