Using R for Gradebook Computations

Caveat: This is not the only way, and certainly not the best way to make a gradebook. You might want to check out xspread, a spreadsheet for unix, or StarOffice which includes an Excel clone.

1. Setup

Setup a directory for your roll files and any other material related to your course. In unix:
mkdir m170
Protect the directory so that nosey students will not have access with the unix command:
chmod 700 m170
Now move to that directory and start up emacs.
cd m170
emacs &

2. Reading in data

Your course supervisor can get you a file of the students in your section. Assume the file looks like this:
Einstein, Albert 0034567
Laird, Nan       0056745
Bernoulli, Jacob 0098453
Camus, Albert    0089452
and that it's called roll_F99 in the m170 directory. It's easiest to add a row of column labels to the top of the file, so edit it in emacs to make it look like this:
Lname     Fname  idno
Einstein, Albert 0034567
Laird, Nan       0056745
Bernoulli, Jacob 0098453
Camus, Albert    0089452
Save the file with C-X C-S.

Now start up R within emacs by typing Meta-X R. Note that the R is uppercase. A question appears in the minibuffer asking which directory to use. Make it your m170 course directory. Soon you are going to need to know more about commands available in R and their proper invocation. Usually you would To read the data into a data frame (like a fancy matrix) use this command in R:

> roll <- read.table("roll_F99",head=TRUE)
If the rows of the data file have different numbers of fields, this step will fail, and it will tell you that there are lines with different numbers of fields. This will happen if some students are listed with a middle name, and others have only two names. Go back to the original file and edit it. If some data are missing, fill in with the capital letters, NA, which R interprets as missing. Save the corrected file and try again:
> roll <- read.table("roll_F99",head=TRUE)
To see the data, type it's name:
> roll  
will display all rows and columns.

3. Adding grades

I find it easiest to put the grades into a column in the text file. I would edit the file to add a column for each grade. I also like to make a last row to hold the possible scores for each homework or quiz.
Lname     Fname  ID      Q1
Einstein, Albert 0034567  4
Laird, Nan       0056745 10
Bernoulli, Jacob 0098453 10
Camus, Albert    0089452  2
Possible Im      0000    10

4. Manipulating grades

Read the roll file back in after each update:
> roll <- read.table("roll_F99",head=TRUE)
  ## attach the data frame so you can refer to each part of it.
  ## The parts can be seen with the names command:
> names(roll)
  [1] "Lname"     "Fname"  "ID"      "Q1"
> attach(roll)
  ##  get summaries:
> summary(Q1)
  ## stem and leaf plots or histograms
> stem(Q1)
> motif()  
  ## before using a good graphics plot, we need to open a 
  ##  graphics device.
> hist(Q1 )
  ## sort output into order:
> detach()
> roll <- roll[order(roll$Lname),]
> attach(roll)
 
Back to MSU Math Department Home Page


Author: Jim Robison-Cox
Last Updated: September 12, 1996