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 / lapply < prev    next >
Encoding:
Text File  |  1997-04-23  |  1.2 KB  |  43 lines

  1.     
  2.     _A_p_p_l_y _a _F_u_n_c_t_i_o_n _O_v_e_r _a _L_i_s_t
  3.     
  4.          lapply(x, fun, ...)
  5.          sapply(x, fun, ..., simplify = TRUE)
  6.     
  7.     _A_r_g_u_m_e_n_t_s:
  8.     
  9.                x : list (or vector for sapply) to be used.
  10.     
  11.              fun : the function to be applied.  In the case of
  12.                    functions like +, %*%, etc., the function
  13.                    name must be quoted.
  14.     
  15.              ... : optional arguments to fun.
  16.     
  17.         simplify : logical; should the result be simplified to a
  18.                    vector if possible?
  19.     
  20.     _D_e_s_c_r_i_p_t_i_o_n:
  21.     
  22.          lapply returns a list of the same length as x.  Each
  23.          element of which is the result of applying fun to the
  24.          corresponding element of x.
  25.     
  26.          sapply is a ``user-friendly'' version of lapply also
  27.          accepting vectors as x, and returning a vector.
  28.     
  29.     _S_e_e _A_l_s_o:
  30.     
  31.          apply, tapply.
  32.     
  33.     _E_x_a_m_p_l_e_s:
  34.     
  35.          x <- list(a = 1:10, beta = exp(-3:3),
  36.                  logic = c(T,F,F,T))
  37.          # compute the list mean for each list element
  38.          lapply(x,mean)
  39.          # median and quartiles for each list element
  40.          lapply(x, quantile, probs = 1:3/4)
  41.          sapply(sapply(3:9, seq), fivenum)
  42.     
  43.