formatC
Formatting Using C-style Formats
Description
Formats numbers and character strings.
Usage
formatC(x, digits = NULL, width = NULL, format = NULL, flag = "", 
    mode = NULL, big.mark = "", big.interval = 3L, small.mark = "", 
    small.interval = 5L, decimal.mark = ".", preserve.width = "individual", 
    zero.print = NULL, drop0trailing = FALSE) 
format.char((x, width = NULL, flag = "-") 
prettyNum(x, big.mark = "", big.interval = 3L, small.mark = "", 
    small.interval = 5L, decimal.mark = ".", preserve.width = c("common", 
    "individual", "none"), zero.print = NULL, drop0trailing = FALSE, 
    is.cmplx = NA, ...) 
Arguments
| x | 
a vector of numbers or character strings.
 | 
| digits | 
an integer. Specifies the number of digits after the decimal point if 
format is "f", "fg", or "e", or the number of 
significant digits if format is "g".
The default value is 1 for integers and 4 for real numbers.  If digits is
a negative value, it is changed to 6.
This value is used to create a format string, such as "%f9.3" (digits=3), 
to pass to the function sprintf.
 | 
| width | 
an integer specifying the total field width. Used to create a format 
string, such as "%f9.3" (width=9), to pass to sprintf.
Set width to a negative value to left justify the number in the field. 
(Setting flag="-" also left justifies the number.) If necessary, the result can have more 
characters than width.
 | 
| format | 
a character string. 
| 
real numbers  |     integers    |  strings  |  | 
"f"             |     "d"           |  "s"        |  | 
"e"             |     "ld"          |                    |  | 
"E"             |                          |                    |  | 
"g"             |                          |                    |  | 
"G"             |                          |                    |  | 
"fg"            |                          |                    |  |  
 |   
If both the format and the mode
arguments are supplied, then format overrides mode.  
The default value is "ld" for integers, "g" for real numbers,
and "s" for character strings.
-  Format "f" gives numbers in the 'xxx.xxx' format.
 -  "e" and "E" give 'n.ddde+nn' or 'n.dddE+nn' (scientific format).
 -  "g" and "G" put the number into scientific format only if it saves space to do so.
  
 | 
| flag | 
a character string. Contains one or more if these characters: '0+- #'.
"0" pads with leading zeros, "-" means left alignment, "+" adds a plus
sign on the front of the number, "#" causes an integer value to be followed
by ".0".
 | 
| mode | 
one of the following character strings.
-  "double"
 -  "real"
 -  "character"
 -  "integer"
  
The default value is determined from the storage mode of x.
 | 
| big.mark | 
a character. Used as a separator in the integer part of a number between the 
number of digits specified by big.interval.
 | 
| big.interval | 
an integer. Specifies the number of digits before the decimal point that are between the
big.marks. The default value is 3, so that the big.mark is a thousands separator.
 | 
| small.mark | 
a character. Used between every small.interval
number of digits after the decimal point.
 | 
| small.interval | 
an integer. Specifies the number of digits between the small.marks. 
The default value is 5.
 | 
| decimal.mark | 
a character. Used as the decimal mark separating the integer part of a number
from the fractional part. The default is ".".
 | 
| preserve.width | 
a character string. Must be one of c("common", "individual", "none"). 
Indicates the width of the string to preserve.
 | 
| zero.print | 
a character string, a logical value, or NULL. 
Indicates how zeros should be formatted.
 | 
| drop0trailing | 
a logical value. If TRUE, the trailing zeros are dropped. The default is FALSE.
 | 
| is.cmplx | 
a logical value. If TRUE, character input is assumed to represent complex numbers.
If NA (the default), it analyzes the input to to determine if it is complex numbers.
 | 
| ... | 
additional arguments to be passed to or from future functions. | 
 
Value
returns a character vector of the same length of x, 
where each input value has been formatted.
References
Kernighan, B. W. and Ritchie, D. M. 1988. The C Programming Language. Second edition. Englewood Cliffs, NJ: Prentice-Hall.
See Also
Examples
formatC(12341234.1234, digits=2, big.mark=",", format="f")
formatC(12341234.1234, digits=4, format="g")
formatC(1.234*10^c(-7,-4,0,3,6), digits=3, format="g")
prettyNum("123.89", decimal.mark=",")