[R] Iterate by Factor - Newbie Question

Thomas Ottaway ottathom at isu.edu
Sun Nov 25 01:55:06 CET 2012


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



More information about the R-help mailing list