Frank Annie
September 9, 2015
Due Date: September 10, 2015 Total Points: 44
1 Assign to an object x the sum of 3 and 5. Find the square root of the sum (2).
x <- 3+5
sqrt(x)
## [1] 2.828427
Table the following numbers in a vector h: 2 4 0 3 1 0 0 1 2 0 (2).
h = c (2,4,0,3,1,0,0,1,2,0)
table (h)
## h
## 0 1 2 3 4
## 4 2 2 1 1
2 The following values are the annual number hurricanes that have hit the United States since 1990. Follow the instructions and answer questions by typing the appropriate R commands.
0 1 1 1 0 2 2 1 3 3 0 0 1 2 6 6 0 1 3 0 1
hurricances <- c(0,1,1,1,0,2,2,1,3,3,0,0,1,2,6,6,0,1,3,0,1)
length(hurricances)
## [1] 21
sum(hurricances)
## [1] 34
3 Answer the following questions by typing the appropriate R commands.
num <-0:25
length(num)
## [1] 26
num_mean <-mean(num)
new_num <-num - num_mean
4 Suppose you keep track of your mileage each time you fill up. At your last 8 fill-ups the mileage was
65311 65624 65908 66219 66499 66821 67145 67447
miles <-c(65311,65624,65908,66219,66499,66821,67145,67447)
diff(miles)
## [1] 313 284 311 280 322 324 302
max(diff(miles))
## [1] 324
min(diff(miles))
## [1] 280
mean(diff(miles))
## [1] 305.1429
5 Create the following sequences using the seq() and rep() functions as appropriate.
rep("a",4)
## [1] "a" "a" "a" "a"
seq(1,100,by=2)
## [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45
## [24] 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91
## [47] 93 95 97 99
rep(1:3,each=3)
## [1] 1 1 1 2 2 2 3 3 3
rep(1:3,c(3,2,1))
## [1] 1 1 1 2 2 3
c(seq(1,5),seq(4,1))
## [1] 1 2 3 4 5 4 3 2 1
6 Read the monthly precipitation dataset from my website (https://uploads.strikinglycdn.com/files/302190/86f2b03b-8fdc-4df3-aeb7-abf37fc535fe/FLMonthlyP.txt) and create a time series graph of April rainfall for the state. (10)
library (ggplot2)
loc <- "https://uploads.strikinglycdn.com/files/302190/86f2b03b-8fdc-4df3-aeb7-abf37fc535fe/FLMonthlyP.txt"
Flmp <- read.table(loc,na.string="-9.900",header=TRUE)
ggplot(Flmp,aes(x=Year, y=Apr)) + geom_line() + ylab("April Rainfall in Fl (in)")