Exam # 2

Arielle Mundy

date()
## [1] "Mon Oct 01 12:59:15 2012"

Due Date: October 5, 2012, 2pm
Total Points: 30; Each question is worth 6 points.

(1) Create a vector called x with elements 2, 3, -5, -9, 3.4, 2.1, 18, -4, -7. Determine the mean, standard deviation, and variance on these values. Extract the third and fifth element of the vector.

x = c(2, 3, -5, -9, 3.4, 2.1, 18, -4, -7)
mean(x)
## [1] 0.3889
sd(x)
## [1] 8.082
var(x)
## [1] 65.33
x[c(3, 5)]
## [1] -5.0  3.4

(2) Create another vector called y with elements 1.7, 1.1, 2.8, -3.2, -2.1, 5, 9, -19, 0. Compute the correlation and covariance between x and y.

y = c(1.7, 1.1, 2.8, -3.2, -2.1, 5, 9, -19, 0)
cor(x, y)
## [1] 0.5225
cov(x, y)
## [1] 33.09

(3) Using the data frame airquality, compute the mean and standard deviation of the ozone concentration.

sapply(airquality[1], mean, na.rm = TRUE)
## Ozone 
## 42.13
sapply(airquality[1], sd, na.rm = TRUE)
## Ozone 
## 32.99

(4) Create a sequence of values from 1.1 to 5.5, by .1. Determine the length of this sequence.

seq(1.1, 5.5, length.out = 45)
##  [1] 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7
## [18] 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4
## [35] 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5

(5) Import the US.txt data file from Blackboard into R and compute the annual average number of Florida hurricanes.

loc = "http://myweb.fsu.edu/jelsner/US.txt"
H = read.table(loc, header = TRUE)
sapply(H[5], mean)
##     FL 
## 0.6813