formatC {base} | R Documentation |
formatC(x, digits = NULL, width = max(0, digits) + 1,
format = NULL, flag = "", mode = NULL)
x |
an atomic numerical or character object, typically a vector of real numbers. |
digits |
the desired number of digits after the decimal point. Default: 2 for integer, 4 for real numbers. If less than 0, the C default of 6 digits is used. |
width |
the total field width; |
format |
equal to |
flag |
format modifier as in Kernighan and Ritchie, 2nd ed.,
page 243.
|
mode |
|
A character object of same size and attributes as x
.
Unlike format
, each number is individually formatted. A for
loop over each element of x
, calling sprintf(...)
is
done in the C function str_signif
.
For character arguments, simple (left or right) padding with white space is done.
This function was originally written by Bill Dunlap and later much improved by Martin Maechler. It was adapted for R by Friedrich Leisch.
format
.
xx <- pi * 10^(-5:4)
options(digits = 4) # only for format
cbind(format(xx), formatC(xx))
cbind(formatC(xx, wid = 9, flag = "-"))
cbind(formatC(xx, dig = 5, wid = 8, format = "f", flag = "0"))
formatC(c("a", "Abc", "no way"), wid = -7) # <=> flag = "-"