[R] flattening return value of tapply

Vadim Ogranovich vograno at arbitrade.com
Sat Dec 29 00:10:34 CET 2001


Dear R-Users,

Does anyone know how to flatten, i.e. convert to a table, a return value of
tapply when its INDEX argument is a list? Here is an example of what I need

> x <- rnorm(100)
> f1 <- rep(c(T,F),50)
> f2 <- c(rep(T,50), rep(F,50))
> y <- tapply(x, list(f1=f1,f2=f2), summary)
> y
       f2
f1      FALSE       TRUE       
  FALSE "Numeric,6" "Numeric,6"
  TRUE  "Numeric,6" "Numeric,6"

# I'd like 'y' to be printed as a table with rows corresponding to factor
combinations.
# The closest I could get to it is this
> t(sapply(y, I))
       Min. 1st Qu.  Median     Mean 3rd Qu.  Max.
[1,] -1.616 -0.5475 0.17450  0.26030  0.9742 2.117
[2,] -2.038 -0.8990 0.02546 -0.13390  0.2461 1.874
[3,] -2.344 -0.5494 0.07578  0.02965  0.5424 1.974
[4,] -1.660 -0.4915 0.41760  0.17750  0.9652 1.629

but this doesn't produce meaningful row names.

Any suggestion?

Thank you,
Vadim

-------------------------------------------------- 
DISCLAIMER 
This e-mail, and any attachments thereto, is intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information.  If you are not the intended recipient of this
e-mail, you are hereby notified that any dissemination, distribution or
copying of this e-mail, and any attachments thereto, is strictly prohibited.
If you have received this e-mail in error, please immediately notify me and
permanently delete the original and any copy of any e-mail and any printout
thereof. 

E-mail transmission cannot be guaranteed to be secure or error-free.  The
sender therefore does not accept liability for any errors or omissions in
the contents of this message which arise as a result of e-mail transmission.

NOTICE REGARDING PRIVACY AND CONFIDENTIALITY 

Knight Trading Group may, at its discretion, monitor and review the content
of all e-mail communications. 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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