[R] Apply or Tapply to Build Set of Tables

From: Sparks, John James <jspark4_at_uic.edu>
Date: Mon, 23 May 2011 19:31:24 -0500


Dear R Helpers,

First, I apologize for asking for help on the first of my topics. I have been looking at the posts and pages for apply, tapply etc, and I know that the solution to this must be ridiculously easy, but I just can't seem to get my brain around it. If I want to produce a set of tables for all the variables in my data, how can I do that without having to type them into the table command one by one. So, I would like to use (t? s? r?)apply to use one command instead of the following set of table commands:

data(infert, package = "datasets")
attach(infert)

table.education<-table(education)
table.age<-table(age)
table.parity<-table(parity)

etc.

To make matters worse, what I subsequently need is the chi-square for each and all of the pairs of variables. Such as:

chi.education.age<-chisq.test(table(education,age))
chi.education.parity<-chisq.test(table(education,parity))
chi.age.parity<-chisq.test(table(age,parity))
etc.

Your guidance would be much appreciated.

--John J. Sparks, Ph.D.



R-help_at_r-project.org 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. Received on Tue 24 May 2011 - 00:33:41 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 May 2011 - 03:50:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive