# This is a brief introduction to R # Open R, and then work through these commands # '#' = comment # '<-' = affect; defines the left hand side to be the right hand side # '>' = prompt of R # basic operations: > 7+5 [1] 12 > 7-5 [1] 2 > 7*5 [1] 35 > 7/5 [1] 1.4 # use the function c() for creating a vector > c(1,2,3) [1] 1 2 3 > c(1,2,3)+c(2,3,4) [1] 3 5 7 > c(1,2,3)*2 [1] 2 4 6 > c(1,2,3)/2 [1] 0.5 1.0 1.5 # create a vector, called 'height', containing 10 values > height <- c(72,70,71,66,73,66,72,72,74,75) > height [1] 72 70 71 66 73 66 72 72 74 75 > mean(height) # compute sample average [1] 71.1 > median(height) # compute sample median [1] 72 > mean(height, trim=0.1) # trimmed mean. [1] 71.25 > var(height) # variance [1] 9.211111 > sqrt(var(height)) # sd [1] 3.034981 > height[2] # the second element of the vector [1] 70 # generate a vector > rep(2,3) # a vector of 2's of length 3 [1] 2 2 2 > seq(1,10, length=20) # a vector of length 20, equally spaced entries [1] 1.000000 1.473684 1.947368 2.421053 2.894737 3.368421 3.842105 [8] 4.315789 4.789474 5.263158 5.736842 6.210526 6.684211 7.157895 [15] 7.631579 8.105263 8.578947 9.052632 9.526316 10.000000 # Importing the data from a file, student.dat # I have this file placed in C:/MyFiles/courses/368/data/student.dat # The directory structure is mine; yours will be different and # so you will have to change the next line correspondingly > student <- read.table("C:/MyFiles/courses/368/data/student.dat",header=T) > attach(student) # access each column of 'student' # various histograms: > hist(weight) > hist(height) > hist(lucky) > hist(random) > stem(lucky) # stem&leaf for illustration > mean(height) > median(height) > mean(height, trim=0.1) > var(height) > range(height) > summary(height) > boxplot(height) > boxplot(random) > q() # quit R > help() # to get help