Sapply                package:memisc                R Documentation

_A _D_i_m_e_n_s_i_o_n _P_r_e_s_e_r_v_i_n_g _V_a_r_i_a_n_t _o_f "_s_a_p_p_l_y" _a_n_d "_l_a_p_p_l_y"

_D_e_s_c_r_i_p_t_i_o_n:

     'Sapply' is equivalent to 'sapply', except that it preserves the
     dimension and dimension names of the argument 'X'. It also
     preserves the dimension of results of the function 'FUN'. It is
     intended for application to results e.g. of a call to 'by'.
     'Lapply' is an analog to 'lapply' insofar as it does not try to
     simplify the resulting 'list' of results of 'FUN'.

_U_s_a_g_e:

     Sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
     Lapply(X, FUN, ...)
       

_A_r_g_u_m_e_n_t_s:

       X: a vector or list appropriate to a call to 'sapply'.

     FUN: a function.

     ...: optional arguments to 'FUN'.

simplify: a logical value; should the result be simplified to a vector
          or matrix if possible?

USE.NAMES: logical; if 'TRUE' and if 'X' is character, use 'X' as names
          for the result unless it had names already.

_V_a_l_u_e:

     If 'FUN' returns a scalar, then the result has the same dimension
     as 'X', otherwise the dimension of the result is enhanced relative
     to 'X'.

_E_x_a_m_p_l_e_s:

     berkeley <- aggregate(Table(Admit,Freq)~.,data=UCBAdmissions)
     berktest1 <- By(~Dept+Gender,
                     glm(cbind(Admitted,Rejected)~1,family="binomial"),
                     data=berkeley)
     berktest2 <- By(~Dept,
                     glm(cbind(Admitted,Rejected)~Gender,family="binomial"),
                     data=berkeley)

     sapply(berktest1,coef)
     Sapply(berktest1,coef)

     sapply(berktest1,function(x)drop(coef(summary(x))))
     Sapply(berktest1,function(x)drop(coef(summary(x))))

     sapply(berktest2,coef)
     Sapply(berktest2,coef)
     sapply(berktest2,function(x)coef(summary(x)))
     Sapply(berktest2,function(x)coef(summary(x)))

