Format(x, digits = NULL, sci = getOption("scipen"), big.mark="",
leading = NULL, zero.form = NULL, na.form = NULL,
fmt = NULL, align = NULL, width = NULL, lang = getOption("lang", "local"), ...)
## S3 method for class 'table':
Format(x, digits = NULL, sci = getOption("scipen"), big.mark="",
leading = NULL, zero.form = NULL, na.form = NULL,
fmt = NULL, align = NULL, width = NULL, lang = getOption("lang", "local"), ...)
## S3 method for class 'matrix':
Format(x, digits = NULL, sci = getOption("scipen"), big.mark="",
leading = NULL, zero.form = NULL, na.form = NULL,
fmt = NULL, align = NULL, width = NULL, lang = getOption("lang", "local"), ...)
## S3 method for class 'default':
Format(x, digits = NULL, sci = getOption("scipen"), big.mark="",
leading = NULL, zero.form = NULL, na.form = NULL,
fmt = NULL, align = NULL, width = NULL, lang = getOption("lang", "local"), ...)
formatC
you will always get this number of digits even if the last digit is 0.NULL
will leave the nuNULL
(default) no special action will be taken.NA
s should be specially formatted.
If set to NULL
(default) no special action will be taken.fmt
, consisting of a list of Format
arguments. See Details.sep = "\\l"
, right alignment by "\\r"
and center alignment by "\\c"
. Mind the backslashes, as if they are omitte"local"
for current locale or "engl"
for english. If left to NULL
, the option "lang"
will be searched for and if not found <fmt
can be used for defining several formats.
Dates can be formatted with any combination of the format codes d
, m
and y
for day, month or year.
Repeting the specific code defines the degree of abbreviation:
d
day of the month without leading zero (1 - 31)
dd
day of the month with leading zero (01 - 31)
ddd
abbreviated name for the day of the week (e.g. Mon) in the current user's language
dddd
full name for the day of the week (e.g. Monday) in the current user's language
m
month without leading zero (1 - 12)
mm
month with leading zero (01 - 12)
mmm
abbreviated month name (e.g. Jan) in the current user's language
mmmm
full month name (e.g. January) in the current user's language
y
year without century, without leading zero (0 - 99)
yy
year without century, with leading zero (00 - 99)
yyyy
year with century. For example: 2005
}
For numeric values there are the following special codes:
e
scientific forces scientific representation of x. The number of digits, alignment
and zero values are respected.
%
percent will divide the given number by 100 and append the %-sign (without a separator).
p
p-value will wrap the function format.pval
and return a p-value format.
*
significance will produce a significance representation of a p-value consisting of * and .,
while the breaks are set according to the used defaults e.g. in lm
as
[0, 0.001] = ***
(0.001, 0.01] = **
(0.01, 0.05] = *
(0.05, 0.1] = .
(0.1,1] =
}
fmt
can as well be an object of class fmt
consisting of a list of all arguments of the function.
This allows the full format to be stored in a variable or as an option and be used as format template subsequently.
If we would want to use an user defined format for counts, we could define a format with a big mark and with 0 digits as:
fmt.count <- structure(list(digits=0, big.mark="'"), class="fmt")
and subsequently call the Format
function with this format:
Format(4231.2, fmt=fmt.count)
which again would return the same as Format(4231.2, digits=0, big.mark="'")
.format
, formatC
, prettyNum
, sprintf
, symnum
,
StrAlign
, StrPad
, Sys.setlocale
,
Weekday
, Month
Format(as.Date(c("2014-11-28", "2014-1-2")), fmt="ddd, d mmmm yyyy")
Format(as.Date(c("2014-11-28", "2014-1-2")), fmt="ddd, d mmmm yyyy", lang="engl")
x <- pi * 10^(-10:10)
Format(x, digits=3, fmt="%", sci=NA)
Format(x, digits=4, sci=c(4, 6), leading = "drop", width=9, align=".")
# format a matrix
m <- matrix(runif(100), nrow=10,
dimnames=list(LETTERS[1:10], LETTERS[1:10]))
Format(m, digits=1)
Run the code above in your browser using DataLab