Hi all, Please, is there any way of controlling factors in row/columns when using ftable/xtabs? As far as I can see, the last cross-clasifing variable in the formula will appear in columns. The previous ones, in rows. For instance, is it possible to make tension and replicate appear in columns? ftable(xtabs(breaks ~ wool + tension + replicate, data = warpbreaks)) After some years using SAS proc tabulate I am afraid I don't get the point with R and cross-tabulation :-( Thanks you very much and Happy New Year! Ricardo --- Ricardo Rodr?guez Your XEN ICT Team
Hi Ricardo,> Please, is there any way of controlling factors in row/columns when using ftable/xtabs? As far as I can see, the last cross-clasifing variable in the formula will appear in columns. The previous ones, in rows. For instance, is it possible to make tension and replicate appear in columns? > > ftable(xtabs(breaks ~ wool + tension + replicate, data = warpbreaks)) > > After some years using SAS proc tabulate I am afraid I don't get the point with R and cross-tabulation :-(You might want to have a look at the reshape package, http://had.co.nz/reshape, which provides a more general and flexible framework for reshaping data in R. The version of warpbreaks I have doesn't have the replicate variable, so unfortunately I can't provide you with example code for this case. However, you should be able to figure it out for your data using the documentation available on the website. Regards, Hadley
Ricardo RodrÃguez - Your XEN ICT Team
2006-Dec-31 18:44 UTC
[R] tabulate: switching columns and rows
>>> hadley wickham<h.wickham at gmail.com> 31/12/2006 19:33 >>>>Hi Ricardo,>You might want to have a look at the reshape package, >http://had.co.nz/reshape, which provides a more general and flexible >framework for reshaping data in R. > >The version of warpbreaks I have doesn't have the replicate variable, >so unfortunately I can't provide you with example code for this case. >However, you should be able to figure it out for your data using the >documentation available on the website.Thanks, Hadley, My fault: I've not provided the line concerning replicate variable. It is included in ?xtabs: warpbreaks$replicate <- rep(1:9, len = 54) It will be great to have an example with these given data. Anyway, I will have a look to reshape at the given site. Thanks a lot! Cheers, Ricardo -- Ricardo Rodr?guez Your XEN ICT Team
Add the argument col.vars = 2:3 to your ftable call. See ?ftable On 12/31/06, Ricardo Rodr?guez <webmaster at xen.net> wrote:> Hi all, > > Please, is there any way of controlling factors in row/columns when using ftable/xtabs? As far as I can see, the last cross-clasifing variable in the formula will appear in columns. The previous ones, in rows. For instance, is it possible to make tension and replicate appear in columns? > > ftable(xtabs(breaks ~ wool + tension + replicate, data = warpbreaks)) > > After some years using SAS proc tabulate I am afraid I don't get the point with R and cross-tabulation :-( > > Thanks you very much and Happy New Year! > > Ricardo > > --- > Ricardo Rodr?guez > Your XEN ICT Team > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >