home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Educational / R-0.49-MI / R-0.49-I / help / base / formatc < prev    next >
Encoding:
Text File  |  1997-04-23  |  2.3 KB  |  69 lines

  1.     
  2.     _F_l_e_x_i_b_l_e _F_o_r_m_a_t_t_i_n_g
  3.     
  4.          formatC(x, digits=NULL, width=max(0,digits)+1,
  5.                  format=NULL, flag="", mode=NULL)
  6.     
  7.     _A_r_g_u_m_e_n_t_s:
  8.     
  9.                x : an atomic numerical or character object, typ-
  10.                    ically a vector of real numbers.
  11.     
  12.           digits : the desired number of digits after the
  13.                    decimal point. Default: 2 for integer, 4 for
  14.                    real numbers.  digits < 0 uses the default
  15.                    for C, namely  6 digits.
  16.     
  17.            width : the total field width; width < 0 means left
  18.                    justify the number in this field (equivalent
  19.                    to flag ="-").  It is possible that the
  20.                    result will be longer than this, but that
  21.                    should only happen in reasonable cases.
  22.     
  23.           format : equal to "d"  (for integers), "f", "e", "E",
  24.                    "g", "G" (for `real'), or "s" (for strings).
  25.                    "f" gives numbers in the usual ``xxx.xxx''
  26.                    format; "e" and "E" give ``n.ddde<nn>'' or
  27.                    ``n.dddE<nn>'' (scientific  format); "g" and
  28.                    "G" put x[i] into scientific format only if
  29.                    it saves space to do so.
  30.     
  31.             flag : format modifier as in Kernighan and Ritchie,
  32.                    2nd ed., p.243.  "0"  pads leading zeros; "-"
  33.                    does left adjustment, others are "+", " ",
  34.                    and "#".
  35.     
  36.             mode : "real",  "integer" or "character".  Default:
  37.                    Automatic.
  38.     
  39.     _V_a_l_u_e:
  40.     
  41.          A character object of same size and attributes as x.
  42.          Unlike format, each number is individually formatted.
  43.          A for loop over each element of x, calling sprintf(...)
  44.          is done in the C function str_signif.
  45.     
  46.          For  character  arguments,  simple (left or right) pad-
  47.          ding with white space is done.
  48.     
  49.     _N_o_t_e:
  50.     
  51.          This function was originally written by Bill Dunlap and
  52.          later much improved by Martin Maechler.  It was adapted
  53.          for R by Friedrich Leisch.
  54.     
  55.     _S_e_e _A_l_s_o:
  56.     
  57.          format.
  58.     
  59.     _E_x_a_m_p_l_e_s:
  60.     
  61.          xx  <- pi*10^(-5:4)
  62.          options(digits=4)   # only for format
  63.          cbind(format(xx), formatC(xx))
  64.          cbind(formatC(xx, wid=9, flag='-'))
  65.          cbind(formatC(xx, dig=5,  wid=8, format="f", flag='0'))
  66.     
  67.          formatC(c("a", "Abc", "no way"), wid = -7)#  -  <=> flag = '-'
  68.     
  69.