date()
## [1] "Thu Sep 15 23:39:28 2022"

Question 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

a. Enter the data into R.

Data1 = c(0, 1, 1, 1, 0, 2, 2, 1, 3, 3, 0, 0, 1, 2, 6, 6, 0, 1, 3, 0, 1)
Data1
##  [1] 0 1 1 1 0 2 2 1 3 3 0 0 1 2 6 6 0 1 3 0 1

b. How many years are there?

length(Data1)
## [1] 21

c. What is the total number of hurricanes over all years?

sum(Data1)
## [1] 34

Question 2. Answer the following questions by typing R commands.

a. Create a vector of numbers starting with 0 and ending with 25.

Data2 = 0:25
Data2
##  [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## [26] 25

b. What is the length of this vector?

length(Data2)
## [1] 26

c. Create a new vector from the original vector by subtracting the mean value over all numbers in the vector.

Data3 = Data2 - mean(Data2)
Data3
##  [1] -12.5 -11.5 -10.5  -9.5  -8.5  -7.5  -6.5  -5.5  -4.5  -3.5  -2.5  -1.5
## [13]  -0.5   0.5   1.5   2.5   3.5   4.5   5.5   6.5   7.5   8.5   9.5  10.5
## [25]  11.5  12.5

Question 3 - Suppose you keep track of your milage 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

a. Enter these numbers into a vector called miles.

miles = c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)
miles
## [1] 65311 65624 65908 66219 66499 66821 67145 67447

b.Use the function diff() to determine the number of miles between fill-ups.

Diff1 = diff(miles)
Diff1
## [1] 313 284 311 280 322 324 302

c. What is the maximum, minimum, and mean number of miles between fill-ups?

Max1 = max(Diff1)
Max1
## [1] 324
Min1 = min(Diff1)
Min1
## [1] 280
Mean2 = mean(Diff1)
Mean2
## [1] 305.1429

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

a. “a”, “a”, “a”, “a”

aa = rep("a", times = 4)
aa
## [1] "a" "a" "a" "a"

b. The odd numbers in the interval from 1 to 100

Odd1 = seq(1, 100, by = 2)
Odd1
##  [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
## [26] 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

c. 1, 1, 1, 2, 2, 2, 3, 3, 3

Rep1 = rep(1:3, each = 3)
Rep1
## [1] 1 1 1 2 2 2 3 3 3

d. 1, 1, 1, 2, 2, 3

Rep2 = rep(1:3, 3:1)
Rep2
## [1] 1 1 1 2 2 3

e. 1, 2, 3, 4, 5, 4, 3, 2, 1

Rep3 = c(seq(1,5),seq(4,1))
Rep3
## [1] 1 2 3 4 5 4 3 2 1

Question 5 Read the monthly precipitation dataset from my website (https://moraviansoundscapes.music.fsu.edu/sites/g/files/upcbnu1806/files/Media/Sciuchetti/ALMonthlyP.txt)

a. What are the wettest and driest values during the month of January?

loc = "https://moraviansoundscapes.music.fsu.edu/sites/g/files/upcbnu1806/files/Media/Sciuchetti/ALMonthlyP.txt"
Precp = read.table(file = loc, header = TRUE)
max2 = max(Precp $ Jan) # wettest value during the month of January
max2
## [1] 13.09
min2 = min(Precp $ Jan) # driest value during the month of January
min2
## [1] 0.8

b. Sort the Feburary rainfall values from “wettest” to “driest”.

neworder = sort(Precp $ Feb, decreasing = TRUE)
neworder
##   [1] 13.35 12.16 11.42 10.69 10.18 10.13  9.85  9.58  9.26  9.23  9.08  8.76
##  [13]  8.60  8.57  8.46  8.24  8.13  7.89  7.80  7.56  7.50  7.46  7.14  7.05
##  [25]  7.02  6.70  6.64  6.57  6.56  6.56  6.39  6.12  6.10  6.09  6.04  6.02
##  [37]  5.90  5.80  5.63  5.59  5.56  5.49  5.29  5.17  5.13  5.08  5.04  5.04
##  [49]  5.02  4.98  4.94  4.92  4.89  4.84  4.80  4.75  4.74  4.69  4.53  4.52
##  [61]  4.47  4.43  4.41  4.39  4.38  4.34  4.32  4.31  4.27  4.26  4.23  4.11
##  [73]  4.05  3.94  3.87  3.82  3.81  3.74  3.73  3.72  3.68  3.60  3.60  3.60
##  [85]  3.56  3.56  3.53  3.46  3.43  3.40  3.37  3.35  3.25  3.24  3.24  3.22
##  [97]  3.21  3.16  3.13  3.00  2.92  2.91  2.82  2.73  2.71  2.69  2.60  2.52
## [109]  2.48  2.45  2.39  2.37  2.29  2.23  2.14  2.09  1.86  1.45  1.41  1.39
## [121]  1.34  1.32  1.29  1.25  0.76

c. Compute the variance of the March rainfall values.

var1 = var(Precp $ Mar)
var1
## [1] 7.41769

d. What is the 95th percentile value of April rainfall?

Per95 = quantile(Precp $ Apr, probs = c(.95))
Per95
##   95% 
## 10.21

e. Create a time series graph of April rainfall.

library("ggplot2")
ggplot(Precp, aes(x = Year, y = Apr)) +
  geom_line() + 
  ylab("April Rainfall (mm) ")