Exam # 2

Lauren Haynes

date()
## [1] "Thu Oct 04 21:48:06 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.

`?`(airquality)
## starting httpd help server ...
## done
head(airquality)
##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6
attach(airquality)
mean(Ozone, na.rm = TRUE)
## [1] 42.13
sd(Ozone, na.rm = TRUE)
## [1] 32.99

(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.

dir()
##  [1] "ArcGIS_Desktop_101_129796.exe"      
##  [2] "Carto Reps.zip"                     
##  [3] "desktop.ini"                        
##  [4] "ESRITipsOnInstallingArcGIS.pdf"     
##  [5] "Exam1 (1).html"                     
##  [6] "Exam1 (1).md"                       
##  [7] "Exam1 (1).Rmd"                      
##  [8] "Exam1.Rmd"                          
##  [9] "Exam2 working.Rmd"                  
## [10] "Exam2.Rmd"                          
## [11] "R-2.15.1-win.exe"                   
## [12] "Representations.zip"                
## [13] "RStudio-0.96.330.exe"               
## [14] "securedoc (1).html"                 
## [15] "securedoc (2).html"                 
## [16] "securedoc (3).html"                 
## [17] "securedoc.html"                     
## [18] "US.txt"                             
## [19] "week 5.pptx"                        
## [20] "Week5_PublicPolicy_LegalIssues.pptx"
H = read.table("US.txt", header = TRUE)
attach(H)
attach(H)
## The following object(s) are masked from 'H (position 3)':
## 
##     All, E, FL, G, MUS, Year
mean(FL)
## [1] 0.6813