format.df
does appropriate rounding and decimal alignment, and outputs
a character matrix containing the formatted data. If x
is a
data.frame, then do each component separately.
If x
is a matrix, but not a data.frame, make it a data.frame
with individual components for the columns.
If a component x$x
is a matrix, then do all columns the same.format.df(x,
digits, dec=NULL, rdec=NULL, cdec=NULL,
numeric.dollar=cdot,
na.blank=FALSE, na.dot=FALSE, blank.dot=FALSE,
col.just=NULL, cdot=FALSE, dcolumn=FALSE, matrix.sep=' ',
scientific=c(-4,4), ...)
digits
significant
digits. dec
is usually preferred.dec
is a scalar, all elements of the matrix will be rounded
to dec
decimal places to the right of the decimal. dec
can also be a matrix
whose elements correspond to x
, for customized rounding of eaccdec
is more commonly used than rdec
)
A vector rdec
must have number of items equal to number of rows of input x
.
rdec
TRUE
to use centered dots rather than ordinary periods in numbers.
The output uses a syntax appropriate for latex
.TRUE
to use blanks rather than NA
for missing values.
This usually looks better in latex
.TRUE
to use David Carlisle's dcolumn
style for
decimal alignment in latex
.
Default is FALSE
. You will probably want to
use dcolumn
if you use rdec
, as a column may then c!dcolumn
. Set to TRUE
to place dollar
signs around numeric values when dcolumn=FALSE
. This
assures that latex
will use minus signs rather than hyphens to indicate
negative numbers. STRUE
to use periods rather than NA
for missing
numeric values.
This works with the sas
convention that periods indicate missing values.TRUE
to use periods rather than blanks for missing character values.
This works with the sas
convention that periods indicate missing values.col.just
must have number of columns equal to
number of columns of the output matrix. When NULL
, the
default, the col.just
attribute of the result is set to
"l"
for character columns x
is a data frame containing a matrix, so that new column names
are constructed from the name of the matrix object and the names of
the individual columns of the matrix, matrix.sep
specifies the
character to use to separate format.default
for details.latexVerbatim
these
arguments are passed to the print
function.x
.
Matrix components of input x
are now just sets of columns of
character matrix.
attr(,col.just)
repeats the input col.just
when provided,
otherwise, it includes the recommended justification for columns of output.
See the discussion of the argument col.just
.
The default justification is "l"
for characters and factors,
"r"
for numeric.
When dcolumn==TRUE
, numerics will have "."
as the justification character.latex
x <- data.frame(a=1:2, b=3:4)
x$m <- matrix(5:8,nrow=2)
names(x)
dim(x)
x
format.df(x)
dim(format.df(x))
Run the code above in your browser using DataCamp Workspace