[R] by() and CrossTable()

Chuck Cleland ccleland at optonline.net
Tue Apr 25 17:07:46 CEST 2006

   I am attempting to produce crosstabulations between two variables for 
subgroups defined by a third factor variable.  I'm using by() and 
CrossTable() in package gmodels.  I get the printing of the tables first 
and then a printing of each level of the INDICES.  For example:


by(warpbreaks, warpbreaks$tension, function(x){CrossTable(x$wool, 
x$breaks > 30, format="SPSS", fisher=TRUE)})

   Is there a way to change this so that the CrossTable() output is 
labeled by the levels of the INDICES variable?  I think this has to do 
with how CrossTable returns output, because the following does what I want:

by(warpbreaks, warpbreaks$tension, function(x){summary(lm(breaks ~ wool, 
data = x))})



Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

More information about the R-help mailing list