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 / switch < prev    next >
Encoding:
Text File  |  1997-04-23  |  1.0 KB  |  36 lines

  1.     
  2.     _S_e_l_e_c_t _O_n_e _o_f _a _L_i_s_t _o_f _A_l_t_e_r_n_a_t_i_v_e_s
  3.     
  4.          switch(EXPR, ...)
  5.     
  6.     _A_r_g_u_m_e_n_t_s:
  7.     
  8.             EXPR : an expression that evaluates to a number or a
  9.                    character string
  10.     
  11.              ... : the list of alternatives, given explicitly
  12.     
  13.     _D_e_s_c_r_i_p_t_i_o_n:
  14.     
  15.          switch evaluates EXPR if the value is an integer
  16.          between 1 and nargs()-1 then the corresponding element
  17.          of ... is evaluated and the result returned.  If EXPR
  18.          returns a character string then that string is used to
  19.          match the names of the elements in .... If there is an
  20.          exact match then that element is evaluated and the
  21.          result returned.
  22.     
  23.     _E_x_a_m_p_l_e_s:
  24.     
  25.          centre <- function(x, type) {
  26.          switch(type,
  27.                  mean=mean(x),
  28.                  median=median(x),
  29.                  trimmed=mean(x, trim=.1))
  30.          }
  31.          x <- rcauchy(10)
  32.          centre(x, "mean")
  33.          centre(x, "median")
  34.          centre(x, "trimmed")
  35.     
  36.