[R] How do you go beyond tapply()?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Mar 30 21:13:53 CEST 2000

Art Salwin <salwin at mitretek.org> writes:

> "An Introduction to R" notes that the function tapply() can
> be used to index a vector by multiple categories. But they
> don't show how to do this.  How does one implement, for
> example, the example in the text in which tax accountants
> are indexed by both state and sex?
> Is there a way to use tapply() to put the vector into bins
> defined by the levels instead of having to exactly match the
> levels?  It seems some sort of historgramming is what's
> needed, but hist() does plots, not just the categorization
> into bins.

Have a look at

tapply(x, list(state,sex), mean)
table(state, sex)
table(cut(age, breakpoints), sex)

   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