date()
## [1] "Sat Oct 06 09:07:44 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
median(x)
## [1] 2
sd(x)
## [1] 8.082
var(x)
## [1] 65.33
x[-3, -5]
## Error: incorrect number of dimensions
(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, mean)
## Ozone Solar.R Wind Temp Month Day
## NA NA 9.958 77.882 6.993 15.804
sapply(airquality, sd)
## Ozone Solar.R Wind Temp Month Day
## NA NA 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.
seq(from = 1.1, to = 5.5, by = 0.1)
## [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
seq(from = 1.1, to = 5.5, length.out = 0.1)
## [1] 1.1
(5) Import the US.txt data file from Blackboard into R and compute the annual average number of Florida hurricanes.
rate = mean(3)
3
## [1] 3