#Set working directory setwd("/Users/Shared/WD/Rdirectory") #Change this pathname to wherever you saved the example data files #Print current working directory getwd() #Example 1 contains simulated weights (lbs) of men #If so desired, you may save output in an external file named example1.txt sink("example1.txt", append=FALSE, split=TRUE) #Read data file into R as a vector example1 = scan("example1.dat") #The sink command does not output the commands so it is helpful to print what is output. Note that source("intro.R", echo=TRUE) will include the commands and output. #Print the words "Raw data" to the screen and output print("Raw data") #Print data example1 print("Mean") #Calculate the sample mean and assign it to an object named xbar xbar=mean(example1) #Print xbar xbar #You do not have to assign the function to an object to see the value print("Standard deviation") sd(example1) #Stop output to example1.txt sink() #Example 2 contains simulated average daily temperatures in State College, PA during May and November #Read data file into R as a data frame example2 = read.table("example2.csv", header=T, sep=",") #Print data example2 #Creates a jpg of graphical output; sink() will not output graphs jpeg("example2.jpg") #To print multiple graphs on a page, split the plotting window into 2 rows and 2 columns par(mfrow=c(2,2)) #Plot a histogram of May hist(example2$may) #Plot a histogram of November hist(example2$november) #Stop output to example2.jpg dev.off() #Note that R is case-sensitive. Both of the following commands will produce errors due to case: Hist(example2$may) #Error in eval.with.vis(expr, envir, enclos) : could not find function "Hist" hist(example2$May) #Error in hist.default(example2$May) : 'x' must be numeric #Because Hist(example2$may) produced an error, R stopped running code from this program. hist(example2$May) therefore was not sourced. I copied the error reported by R for your reference. By the reported error, it is not clear that the problem is simply a matter of case; it is only clear that there is a problem.