[R] Is there a "by()" function in R like in S?
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Jan 31 13:25:45 CET 2000
Sven Garbade <garbade at mip.paed.uni-muenchen.de> writes:
> > by(data, year, summary)
>
> where "data" is a matrix containing the variable "year". After grouping
> the matrix to variable "year", the function "summary" is applied to each
> group.
It's not in there, but it shouldn't be too hard to write one. Here's
a start:
by <- function(data, INDICES, FUN, ...)
{
ee <- substitute(tapply(1:nrow(data), INDICES, FUNx))
FUNx <- function(x) FUN(data[x,], ...)
ans <- eval(ee, data)
class(ans)<-"by"
}
Now go and write print.by ...
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list