Problem Set # 1

Rebekah Jones

date()
## [1] "Tue Sep 20 22:20:31 2016"

Due Date: September 20, 2016

Total Points: 42

1 The following values are the annual number hurricanes that have hit the United States since 1990. Answer the questions by typing R commands.

0 1 1 1 0 2 2 1 3 3 0 0 1 2 6 6 0 1 3 0 1

  1. Enter the data into R. (2)
hits<-c(0,1,1,1,0,2,2,1,3,3,0,0,1,2,6,6,0,1,3,0,1)
  1. How many years are there? (2)
length(hits)
## [1] 21

b = 21

  1. What is the total number of hurricanes over all years? (2)
sum(hits)
## [1] 34

c=34

2 Answer the following questions by typing R commands.

  1. Create a vector of numbers starting with 0 and ending with 25. (2)
seq1<- (seq(from = 0, to = 25, by = 1))
  1. What is the length of this vector? (2)
length(seq1)
## [1] 26

b = 26

  1. Create a new vector from the original vector by subtracting the mean value over all numbers in the vector. (2)
seqoriginal<- seq1
seq2 <- seq1
mean(seq2)
## [1] 12.5
seq2 = seq1-mean(seq1)

3 Suppose you keep track of your mileage each time you fill your car’s gas tank. At your last 8 fill-ups the mileage was

65311 65624 65908 66219 66499 66821 67145 67447

  1. Enter these numbers into a vector called miles. (2)
miles<- c(65311,65624,65908,66219,66499,66821,67145,67447)
  1. Use the function diff() to determine the number of miles between fill-ups. (2)
ford<- diff(miles)

[1] 313 284 311 280 322 324 302

  1. What is the maximum, minimum, and mean number of miles between fill-ups? (3)
mean(ford)
## [1] 305.1429
max(ford)
## [1] 324
min(ford)
## [1] 280

mean(ford) [1] 305.1429 max(ford) [1] 324 min(ford) [1] 280

4 Create the following sequences using the seq() and rep() functions as appropriate.

  1. “a”, “a”, “a”, “a” (2)
rep("a", 4)
## [1] "a" "a" "a" "a"
  1. The odd numbers in the interval from 1 to 100 (2)
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
  1. 1, 1, 1, 2, 2, 2, 3, 3, 3 (2)
rep(1:3, each=3)
## [1] 1 1 1 2 2 2 3 3 3
  1. 1, 1, 1, 2, 2, 3 (2)
rep(1:3, c(3,2,1))
## [1] 1 1 1 2 2 3
  1. 1, 2, 3, 4, 5, 4, 3, 2, 1 (3) Hint: Use the c() function.
c(1:5,4:1)
## [1] 1 2 3 4 5 4 3 2 1

5 Read the monthly precipitation dataset from my website (http://myweb.fsu.edu/jelsner/temp/data/FLMonthlyP.txt).

loc<- "http://myweb.fsu.edu/jelsner/temp/data/FLMonthlyP.txt"
mdata<- read.table(file = loc, header = TRUE)
  1. What are the wettest and driest values during the month of January? (2)
range(mdata$Jan)
## [1] 0.34 8.36

min = 0.34, max = 8.36

  1. Sort the February rainfall values from wettest to driest. (2)
sort(mdata$Feb, decreasing=TRUE)
##   [1] 8.58 7.46 6.71 6.00 5.92 5.78 5.65 5.58 5.46 5.46 5.42 5.38 5.11 4.96
##  [15] 4.87 4.81 4.76 4.73 4.67 4.58 4.57 4.48 4.37 4.31 4.27 4.26 4.24 4.21
##  [29] 4.18 4.18 4.17 4.09 4.03 4.00 3.96 3.94 3.92 3.92 3.92 3.81 3.79 3.72
##  [43] 3.60 3.57 3.55 3.55 3.52 3.51 3.44 3.39 3.36 3.36 3.32 3.30 3.24 3.22
##  [57] 3.17 3.17 3.17 3.15 3.10 3.04 3.03 3.02 3.02 2.99 2.94 2.74 2.74 2.72
##  [71] 2.71 2.60 2.60 2.54 2.50 2.49 2.48 2.36 2.34 2.32 2.30 2.30 2.22 2.16
##  [85] 2.15 2.14 2.11 2.11 2.06 2.01 2.01 1.99 1.97 1.85 1.84 1.82 1.81 1.78
##  [99] 1.76 1.69 1.60 1.59 1.50 1.39 1.39 1.38 1.35 1.30 1.28 1.25 1.19 1.17
## [113] 1.14 1.12 1.07 0.95 0.85 0.80 0.74 0.29
  1. Compute the variance of the March rainfall values. (2)
var(mdata$Mar)
## [1] 3.767958
  1. What is the 95th percentile value of April rainfall? (2)
quantile(mdata$Apr, c(0.95))
##    95% 
## 5.4515

d= 3.767958

  1. Create a time series graph of April rainfall. (4)
library("ggplot2")
ggplot(mdata, aes(x = Year, y = Apr)) +
  geom_line() +
  ylab("April Precipitation in Florida (in)")