# This sample program shows how to 
# 1. input data set into R,
# 2. calculate numerical summaries:
#    mean, median, variance, standard deviation
#    5-point"summary, range, IQR=Q3-Q1
# 3. produce graphical displays:
#    Stem-and-leaf plot, Histograms, Box-plots, scatter plot, Q-Q plot
#
# You need to change the working dir from "File|Change dir" to the dir
# where the data is located. Here the data set = data2.txt
#(Save to your local drive as an ASCII file)

t<-matrix(scan("data2.txt"),ncol=2,byrow=T) 

# The data has 2 columns and read by row

exam <-data.frame(mid=t[,1],final=t[,2])
t
exam

# Contrast the difference between "t" and "exam"

attach(exam)  # Use "exam" as our working dataset

# Numerical Summaries
summary(exam)
mean(exam)
var(exam); var(mid); var(final)


# Graphical Displays
par(mfrow=c(2,2));    # Setup the graphical device
# I use "mid" as the variable, you can try the command on "final"
hist(mid); boxplot(mid); qqnorm(mid);
plot(density(mid));
stem(mid);


boxplot(mid,final)
plot(mid, final)
hist(mid,c(0,10,20,30,40,50,60,70,80,90,100))
hist(final,c(0,10,20,30,40,50,60,70,80,90,100))
qqplot(mid,final)
qqnorm(mid, main="Normal QQ plot for Mid")
qqnorm(final, main="Normal QQ plot for Final" )


detach(exam) 
# "exam" is no longer used


# Then Exit R without saving workpace image.

# See Statistics and Graphics Section of R reference Card (refcard.pdf)
# by Jonathan Baron