Thanks for the suggestions Jeff.  I have added some text below that will
hopefully clarify my question and more closely follow the guidelines.
Barry
--

Sorry for the confusing first post. I have edited for clarity and included
some sample data.

Clarified summary of problem: I have an excel spreadsheet has a row for
every student registered at the university for each term since fall 2010
with the following information about each student in columns: Term, Campus,
College, Major, Gender, Ethnicity, Age.

My goal is to be able to generate a print ready report out of R that will
build some output quality tables for printing. I don't care if they are
PDF, HTML, etc., as long as I can print them and they are somewhat
attractive. So far, I have imported the spreadsheet into R as a CSV I have
been attempting to do this with the "GridExtra" library with some success.

I have 3 problems thus far: 1. If the count for a cell in the table is
zero, it does not appear in the table; 2. I am unable to understand how to
create more complex tables: for example a table that; 3. I am not able to
create a column and row total.

An example table is shown below:

       ------Campus S-------|---------Campus M-----|-----Campus O------
       2010    2011    2012   2010    2011    2012  2010    2011
2012   Total column

COE

    A
    B
    C

COBA

    A
    B
    C

Totals -->

Thus far my efforts have been something like this (small sample dataset):

Term <- c("Fall 2010", "Fall 2010", "Fall 2011", "Fall 2011", "Fall
2011", "Fall 2011", "Fall 2010",
          "Fall 2010", "Fall 2011", "Fall 2011", "Fall 2011", "Fall 2011")
Campus <- c("S", "M", "O", "O", "S", "S", "O", "S", "S", "O", "S", "S")
College <- c("COE", "COBA", "COBA", "COLFA", "COE", "COBA", "COBA",
"COBA", "COBA", "COBA", "COBA", "COLFA")
Major <- c("A", "B", "C", "A", "C", "C", "A", "C", "C", "A", "C", "C")
Gender <- c("M", "F", "F", "F", "F", "M", "F", "F", "M", "F", "F", "M")
Ethnicity <- c("B", "W", "W", "B", "B", "W", "B", "W", "W", "B", "W", "W")
Age <- c(25, 27, 44, 62, 23, 36, 42, 44, 55, 65, 33, 20)
mydata <- data.frame(Term, Campus, College, Major, Gender, Ethnicity, Age)
mydata

termxcamp.table <- table(mydata$Term, mydata$Campus)
termxcoll.table <- table(mydata$Term, mydata$College)

library(gridExtra)
plot.new()
grid.table(termxcamp.table)
plot.new()
grid.table(termxcoll.table)



On Thu, Jul 3, 2014 at 3:05 AM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

> Your question is vague. You say you have code that does what you want it
> to, yet do not share an example of it as a starting point, or explain what
> you have not been able to do. It is the nature of the Internet that you
> have to be precise in describing your problems and desired solutions.
>
> When I read "populate tables" I think of input processing, yet you say you
> already have code, suggesting that you have successfully read in your data
> to R.
>
> Since you attempted to attach Excel files to a posting, I assume you have
> not yet read the Posting Guide mentioned at the bottom of this (or any
> other email from this mailing list) since that document warns against
> attaching non-text files. Please read it. Also, we tend to "speak" in R on
> this list rather than translating from other programming dialects,
> especially proprietary ones... that is your responsibility. Sort of like
> foreign language immersion. :-)
>
> A word to the wise... it is significantly easier to read in CSV data than
> XLS or XLSX data in R. For getting started in R I highly recommend
> exporting your XLSX data to CSV.
>
> You may find [1] helpful in formulating a reproducible example to get the
> ball rolling more effectively.
>
> [1]
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
> Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On July 2, 2014 7:33:12 PM PDT, Barry Lambert <barrylamb...@gmail.com>
> wrote:
> >I am a new convert to R (from SAS).  I am a research scientist and most
> >of
> >my
> >use of SAS was in data analysis.  Recently, I have been wanting to use
> >R to
> >create a simple, reliable way to summarize a dataset of student
> >demographics
> >for a university.
> >The spreadsheet has a row for every student registered at the
> >university for
> >each term since fall 2010 with the following information about each
> >student
> >in columns:
> >Columns are the following: Term, College, Program, Campus, Gender,
> >Ethnicity, Age.
> >
> >I have created summary tables in Excel using if/then type formulas to
> >select
> >data and count the number of female students in program A at location
> >3,
> >etc.
> >
> >I have written some R code to create some figures that generally meet
> >my
> >needs.
> >I would like to find a way to have R populate some tables with this
> >type of
> >information.
> >
> >An example of my excel sheets are attached.
> >
> >
> >Any suggestions will be appreciated.
> >
> >
> >------------------------------------------------------------------------
> >
> >______________________________________________
> >R-help@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.
>
>


-- 
--
Barry Lambert
Mobile/Text: 254-485-5328

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to