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 / Round < prev    next >
Encoding:
Text File  |  1997-04-23  |  1.4 KB  |  48 lines

  1.     
  2.     _R_o_u_n_d_i_n_g _o_f _N_u_m_b_e_r_s
  3.     
  4.          ceiling(x)
  5.          floor(x)
  6.          round(x, digits=0)
  7.          signif(x, digits)
  8.          trunc(x)
  9.     
  10.     _D_e_s_c_r_i_p_t_i_o_n:
  11.     
  12.          ceiling takes a single numeric argument x and returns a
  13.          numeric vector containing the smallest integers not
  14.          less than the corresponding elements of x.
  15.     
  16.          floor takes a single numeric argument x and returns a
  17.          numeric vector containing the largest integers not
  18.          greater than the corresponding elements of x.
  19.     
  20.          round rounds the values in its first argument to the
  21.          specified number of decimal places (default 0).
  22.     
  23.          signif rounds the values in its first argument to the
  24.          specified number of significant digits.
  25.     
  26.          trunc takes a single numeric argument x and returns a
  27.          numeric vector containing the integers by truncating
  28.          the values in x toward 0.
  29.     
  30.     _S_e_e _A_l_s_o:
  31.     
  32.          as.integer.
  33.     
  34.     _E_x_a_m_p_l_e_s:
  35.     
  36.          print(x1 <- seq(-2,4, by =.5))
  37.          x1[trunc(x1) != floor(x1)]
  38.          x1[round(x1) != floor(x1 + .5)]
  39.          all(trunc(x1) == as.integer(x1)) # TRUE
  40.          non.int <- ceiling(x1) != floor(x1)
  41.          all(non.int == (ceiling(x1) != trunc(x1) | trunc(x1) != floor(x1))) # TRUE
  42.          all((signif(x1, 1) != round(x1)) == (non.int & abs(x1)<1)) # TRUE
  43.     
  44.          x2 <- pi*100^(-1:3)
  45.          round(x2, 3)
  46.          signif(x2, 3)
  47.     
  48.