date()
## [1] "Fri Oct 05 12:59:10 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)
x
## [1] 2.0 3.0 -5.0 -9.0 3.4 2.1 18.0 -4.0 -7.0
mean(x)
## [1] 0.3889
sd(x)
## [1] 8.082
var(x)
## [1] 65.33
x[3]
## [1] -5
x[5]
## [1] 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)
y
## [1] 1.7 1.1 2.8 -3.2 -2.1 5.0 9.0 -19.0 0.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.
`?`(airquality)
## starting httpd help server ...
## done
sapply(airquality, mean, na.rm = TRUE)
## Ozone Solar.R Wind Temp Month Day
## 42.129 185.932 9.958 77.882 6.993 15.804
sapply(airquality, sd, na.rm = TRUE)
## Ozone Solar.R Wind Temp Month Day
## 32.988 90.058 3.523 9.465 1.417 8.865
(4) Create a sequence of values from 1.1 to 5.5, by .1. Determine the length of this sequence.
t = seq(from = 1.1, to = 5.5, by = 0.1)
t
## [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
n = length(t)
n
## [1] 45
(5) Import the US.txt data file from Blackboard into R and compute the annual average number of Florida hurricanes.
getwd()
## [1] "C:/Users/mckenmic/Downloads"
H = read.table("US.txt", header = TRUE)
attach(H)
rate = mean(FL)
rate
## [1] 0.6813