[R] Iterate by Factor - Newbie Question

jim holtman jholtman at gmail.com
Sun Nov 25 04:20:54 CET 2012


Hard to tell without the rest of the data.  You can probably use
'merge' to add the data from the second file to the first.  If you
want printed pages, then you can just have a 'for' loop that goes
through the dataframe creating the lines of output you want on the
report and then insert a 'form feed' character between the pages and
then you just route the text file to a printer.

SO if this does not solve your problem, more information/detail would
be required.

On Sat, Nov 24, 2012 at 7:55 PM, Thomas Ottaway <ottathom at isu.edu> wrote:
> I have end of semester teaching evaluation data of the following form:
>
>> head(evaluations)
>    Course Prefix Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14
> 1 2330301      2  4  3  3  3  4  4  1  2  5   4   1   1   1   1
> 2 2330301      2  3  3  3  3  3  5  1  2  5   8   1   1   1   1
> 3 2330301      2  4  4  3  3  4  4  2  2  5   9   1   1   1   1
> 4 2330301      2  2  1  1  3  4  5  1  2  5   8   1   1   1   1
> 5 2330301      2  4  3  4  4  4  3  1  3  5   8   1   3   1   1
> 6 2330301      2  3  4  2  2  4  2  2  2  5   9   1   1   1   1
>
> There are 90 levels, representing each of the courses taught in my
> college.  I have figured out how to process by level using:
>
> # Read in raw data files
> setwd("College\\Evals")
> evaluations <- read.csv(file="spring2012.csv",head=TRUE,sep=",")
>
> # Determine and display factors
> courses = factor(evaluations$Course)
> table(courses)
>
> # Get summary statistics by factor
> by(evaluations, courses, summary)
>
> What I would like to do is create a separate printed page for each
> course so that I can hand them out to the faculty.  I would like each
> page to contain a title, the number of respondents, some summary
> statistics, and a histogram.  I need to be able to use a second
> dataframe containing the course (id), course title, and faculty member
> name.  Despite a few hours of searching on Google and pecking away at
> the keyboard, I have been unable to figure out how to replace
> "summary" in the above "by" statement with a function that will accept
> and process the necessary data.  Am I even on the right track?  Any
> pointers will be greatly appreciated, this is my first foray into R.
>
> Tom
> --
> Thomas A. Ottaway, Ph.D.
> Interim Dean
> Professor of Computer Information Systems
> College of Business
> Idaho State University
> 921 South 8th Street
> Pocatello, ID  83209-8020
> (208) 282-2601
>
> ______________________________________________
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.




More information about the R-help mailing list