home *** CD-ROM | disk | FTP | other *** search
-
- _A_p_p_l_y _a _F_u_n_c_t_i_o_n _O_v_e_r _a _L_i_s_t
-
- lapply(x, fun, ...)
- sapply(x, fun, ..., simplify = TRUE)
-
- _A_r_g_u_m_e_n_t_s:
-
- x : list (or vector for sapply) to be used.
-
- fun : the function to be applied. In the case of
- functions like +, %*%, etc., the function
- name must be quoted.
-
- ... : optional arguments to fun.
-
- simplify : logical; should the result be simplified to a
- vector if possible?
-
- _D_e_s_c_r_i_p_t_i_o_n:
-
- lapply returns a list of the same length as x. Each
- element of which is the result of applying fun to the
- corresponding element of x.
-
- sapply is a ``user-friendly'' version of lapply also
- accepting vectors as x, and returning a vector.
-
- _S_e_e _A_l_s_o:
-
- apply, tapply.
-
- _E_x_a_m_p_l_e_s:
-
- x <- list(a = 1:10, beta = exp(-3:3),
- logic = c(T,F,F,T))
- # compute the list mean for each list element
- lapply(x,mean)
- # median and quartiles for each list element
- lapply(x, quantile, probs = 1:3/4)
- sapply(sapply(3:9, seq), fivenum)
-
-