home *** CD-ROM | disk | FTP | other *** search
-
- _F_l_e_x_i_b_l_e _F_o_r_m_a_t_t_i_n_g
-
- formatC(x, digits=NULL, width=max(0,digits)+1,
- format=NULL, flag="", mode=NULL)
-
- _A_r_g_u_m_e_n_t_s:
-
- x : an atomic numerical or character object, typ-
- ically a vector of real numbers.
-
- digits : the desired number of digits after the
- decimal point. Default: 2 for integer, 4 for
- real numbers. digits < 0 uses the default
- for C, namely 6 digits.
-
- width : the total field width; width < 0 means left
- justify the number in this field (equivalent
- to flag ="-"). It is possible that the
- result will be longer than this, but that
- should only happen in reasonable cases.
-
- format : equal to "d" (for integers), "f", "e", "E",
- "g", "G" (for `real'), or "s" (for strings).
- "f" gives numbers in the usual ``xxx.xxx''
- format; "e" and "E" give ``n.ddde<nn>'' or
- ``n.dddE<nn>'' (scientific format); "g" and
- "G" put x[i] into scientific format only if
- it saves space to do so.
-
- flag : format modifier as in Kernighan and Ritchie,
- 2nd ed., p.243. "0" pads leading zeros; "-"
- does left adjustment, others are "+", " ",
- and "#".
-
- mode : "real", "integer" or "character". Default:
- Automatic.
-
- _V_a_l_u_e:
-
- 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) pad-
- ding with white space is done.
-
- _N_o_t_e:
-
- This function was originally written by Bill Dunlap and
- later much improved by Martin Maechler. It was adapted
- for R by Friedrich Leisch.
-
- _S_e_e _A_l_s_o:
-
- format.
-
- _E_x_a_m_p_l_e_s:
-
- 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 = '-'
-
-