date()
## [1] "Thu Sep 10 19:36:29 2020"
library("ggplot2")
Due Date: September 13, 2020
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
anHur = c(0, 1, 1, 1, 0, 2, 2, 1, 3, 3, 0, 0, 1, 2, 6, 6, 0, 1, 3, 0, 1)
20 Years
Year = 1990:2010
AnHur.df = data.frame(Year, anHur)
AnHur.df
## Year anHur
## 1 1990 0
## 2 1991 1
## 3 1992 1
## 4 1993 1
## 5 1994 0
## 6 1995 2
## 7 1996 2
## 8 1997 1
## 9 1998 3
## 10 1999 3
## 11 2000 0
## 12 2001 0
## 13 2002 1
## 14 2003 2
## 15 2004 6
## 16 2005 6
## 17 2006 0
## 18 2007 1
## 19 2008 3
## 20 2009 0
## 21 2010 1
TotYear = length(AnHur.df$Year)
TotYear
## [1] 21
sum(anHur)
## [1] 34
2 Answer the following questions by typing R commands.
num = 0:25
num
## [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
length(num)
## [1] 26
numMean = mean(num)
newNum = num - numMean
newNum
## [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
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
miles = c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)
miledif = diff(miles)
miledif
## [1] 313 284 311 280 322 324 302
summary(miledif)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 280.0 293.0 311.0 305.1 317.5 324.0
4 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 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
repnum = c(rep(1,3), rep(2,3), rep(3,3))
repnum
## [1] 1 1 1 2 2 2 3 3 3
seqx = c(rep(1,3), rep(2,2), 3)
seqx
## [1] 1 1 1 2 2 3
newseq = c(rep(1:5), rep(4:1))
newseq
## [1] 1 2 3 4 5 4 3 2 1
5 Read the monthly precipitation dataset from my website (https://moraviansoundscapes.music.fsu.edu/sites/g/files/upcbnu1806/files/Media/Sciuchetti/ALMonthlyP.txt).
setwd("C:/Rdata")
getwd()
## [1] "C:/Rdata"
input = "C:/RData/ALMonthlyP.txt"
ALp = read.table(input, na.string = "-9.900",
header = TRUE)
sort(ALp$Jan)
## [1] 0.34 0.42 0.63 0.70 0.72 0.73 0.85 0.90 0.92 0.96 0.97 1.11 1.12 1.12 1.18
## [16] 1.19 1.26 1.28 1.32 1.33 1.39 1.45 1.47 1.48 1.52 1.61 1.64 1.65 1.69 1.69
## [31] 1.76 1.80 1.80 1.82 1.83 1.84 1.84 1.85 1.85 1.89 1.91 1.92 1.94 1.96 2.00
## [46] 2.10 2.13 2.19 2.26 2.27 2.30 2.33 2.37 2.40 2.41 2.42 2.43 2.52 2.59 2.69
## [61] 2.70 2.70 2.75 2.85 2.95 3.00 3.02 3.07 3.14 3.14 3.17 3.18 3.21 3.26 3.28
## [76] 3.29 3.34 3.39 3.43 3.47 3.48 3.57 3.57 3.61 3.65 3.73 3.82 3.91 3.91 3.93
## [91] 3.97 4.01 4.02 4.02 4.04 4.11 4.14 4.26 4.27 4.41 4.44 4.52 4.60 4.64 4.66
## [106] 4.88 4.91 4.96 5.06 5.17 5.27 5.35 5.38 5.38 5.66 5.83 5.91 6.36 6.55 8.36
sort(ALp$Feb)
## [1] 0.29 0.74 0.80 0.85 0.95 1.07 1.12 1.14 1.17 1.19 1.25 1.28 1.30 1.35 1.38
## [16] 1.39 1.39 1.50 1.59 1.60 1.69 1.76 1.78 1.81 1.82 1.84 1.85 1.97 1.99 2.01
## [31] 2.01 2.06 2.11 2.11 2.14 2.15 2.16 2.22 2.30 2.30 2.32 2.34 2.36 2.48 2.49
## [46] 2.50 2.54 2.60 2.60 2.71 2.72 2.74 2.74 2.94 2.99 3.02 3.02 3.03 3.04 3.10
## [61] 3.15 3.17 3.17 3.17 3.22 3.24 3.30 3.32 3.36 3.36 3.39 3.44 3.51 3.52 3.55
## [76] 3.55 3.57 3.60 3.72 3.79 3.81 3.92 3.92 3.92 3.94 3.96 4.00 4.03 4.09 4.17
## [91] 4.18 4.18 4.21 4.24 4.26 4.27 4.31 4.37 4.48 4.57 4.58 4.67 4.73 4.76 4.81
## [106] 4.87 4.96 5.11 5.38 5.42 5.46 5.46 5.58 5.65 5.78 5.92 6.00 6.71 7.46 8.58
var(ALp$Mar)
## [1] 3.767958
quantile(ALp$Apr, prob = .95)
## 95%
## 5.4515
ggplot(ALp, aes(x = Year, y = Apr)) +
geom_line() +
ylab("April Rainfall in Alabama (in)")