| 1 |
\name{Sapply} |
| 2 |
\alias{Lapply} |
| 3 |
\alias{Sapply} |
| 4 |
\title{A Dimension Preserving Variant of "sapply" and "lapply"} |
| 5 |
\description{ |
| 6 |
\code{Sapply} is equivalent to \code{\link{sapply}}, except |
| 7 |
that it preserves the dimension and dimension names of the |
| 8 |
argument \code{X}. It also preserves the dimension of |
| 9 |
results of the function \code{FUN}. |
| 10 |
It is intended for application to results e.g. |
| 11 |
of a call to \code{\link{by}}. \code{Lapply} is an analog |
| 12 |
to \code{lapply} insofar as it does not try to simplify |
| 13 |
the resulting \code{list} of results of \code{FUN}. |
| 14 |
} |
| 15 |
\usage{ |
| 16 |
Sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) |
| 17 |
Lapply(X, FUN, ...) |
| 18 |
} |
| 19 |
\arguments{ |
| 20 |
\item{X}{a vector or list appropriate to a call to \code{sapply}.} |
| 21 |
\item{FUN}{a function.} |
| 22 |
\item{...}{optional arguments to \code{FUN}.} |
| 23 |
\item{simplify}{a logical value; should the result be simplified to a vector or matrix if possible?} |
| 24 |
\item{USE.NAMES}{logical; if \code{TRUE} and if \code{X} is character, use \code{X} as names for the result unless it had names already.} |
| 25 |
} |
| 26 |
|
| 27 |
\value{ |
| 28 |
If \code{FUN} returns a scalar, then the result has the same dimension |
| 29 |
as \code{X}, otherwise the dimension of the result is enhanced relative |
| 30 |
to \code{X}. |
| 31 |
} |
| 32 |
|
| 33 |
\examples{ |
| 34 |
berkeley <- Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions) |
| 35 |
berktest1 <- By(~Dept+Gender, |
| 36 |
glm(cbind(Admitted,Rejected)~1,family="binomial"), |
| 37 |
data=berkeley) |
| 38 |
berktest2 <- By(~Dept, |
| 39 |
glm(cbind(Admitted,Rejected)~Gender,family="binomial"), |
| 40 |
data=berkeley) |
| 41 |
|
| 42 |
sapply(berktest1,coef) |
| 43 |
Sapply(berktest1,coef) |
| 44 |
|
| 45 |
sapply(berktest1,function(x)drop(coef(summary(x)))) |
| 46 |
Sapply(berktest1,function(x)drop(coef(summary(x)))) |
| 47 |
|
| 48 |
sapply(berktest2,coef) |
| 49 |
Sapply(berktest2,coef) |
| 50 |
sapply(berktest2,function(x)coef(summary(x))) |
| 51 |
Sapply(berktest2,function(x)coef(summary(x))) |
| 52 |
} |
| 53 |
\keyword{utilities} |
| 54 |
\keyword{misc} |