Problem Set # 1

Joshua Osula

date()
## [1] "Sat Sep 12 16:28:35 2020"

1 The following values are the annual number hurricanes that have hit the United States since 1990 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. (2)

Hurry = c(0, 1, 1, 1, 0, 2, 2, 1, 3, 3, 0, 0, 1, 2, 6, 6, 0, 1, 3, 0, 1)
Hurry
##  [1] 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)
Year = 1990:2010
Hurry = data.frame(Year, Hurry)
Hurry
##    Year Hurry
## 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
length(Hurry$Year)
## [1] 21
  1. What is the total number of hurricanes over all years? (2)
sum(Hurry)
## [1] 42034

NB I don’t know why the sum showed 42034 when i was knitting it to html. When i ran it the first time it showed 34

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

Numb = c(0:25)  
  1. What is the length of this vector? (2)
length(Numb)
## [1] 26
  1. Create a new vector from the original vector by subtracting the mean value over all numbers in the vector. (2)
mean(Numb)
## [1] 12.5
Numb - mean(Numb)
##  [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

  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)
?diff
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)
summary(miles)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   65311   65837   66359   66372   66902   67447

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)
rev(100:1)
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100
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
  1. 1, 1, 1, 2, 2, 2, 3, 3, 3 (2)
rep = c(rep(1,3), rep(2,3), rep(3,3))
rep
## [1] 1 1 1 2 2 2 3 3 3
  1. 1, 1, 1, 2, 2, 3 (2)
repd = c(rep(1,3), rep(2,2), rep(3,1))
repd
## [1] 1 1 1 2 2 3
  1. 1, 2, 3, 4, 5, 4, 3, 2, 1 (3) Hint: Use the c() function.
seq = c(rep(1:5), rep(4:1))
seq
## [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).

library(ggplot2)
input = ("https://moraviansoundscapes.music.fsu.edu/sites/g/files/upcbnu1806/files/Media/Sciuchetti/ALMonthlyP.txt")
DRIPDROP = read.table(input, na.string = "-9.900", header = TRUE)
  1. What are the wettest and driest values during the month of January? (2)
sort (DRIPDROP$Jan, decreasing = TRUE)
##   [1] 13.09 12.16 11.61 11.12 10.38 10.19  9.87  9.75  9.66  8.99  8.67  8.61
##  [13]  8.44  8.40  8.00  7.66  7.60  7.41  7.37  7.24  7.11  7.07  7.02  7.00
##  [25]  6.97  6.87  6.79  6.75  6.74  6.74  6.55  6.46  6.41  6.38  6.27  6.21
##  [37]  6.11  6.11  6.04  5.92  5.89  5.84  5.79  5.73  5.71  5.70  5.51  5.47
##  [49]  5.46  5.40  5.33  5.31  5.28  5.25  4.96  4.94  4.94  4.92  4.88  4.85
##  [61]  4.79  4.75  4.74  4.74  4.74  4.73  4.65  4.62  4.49  4.38  4.37  4.36
##  [73]  4.32  4.25  4.24  4.23  4.16  4.13  4.08  4.02  4.01  3.99  3.85  3.73
##  [85]  3.71  3.68  3.64  3.61  3.60  3.50  3.47  3.41  3.41  3.29  3.18  3.16
##  [97]  3.07  3.02  3.01  2.99  2.97  2.87  2.86  2.84  2.77  2.73  2.70  2.68
## [109]  2.64  2.64  2.62  2.51  2.48  2.48  2.47  2.45  2.31  2.29  2.17  2.14
## [121]  1.94  1.72  1.70  1.57  0.80
range (DRIPDROP$Jan)
## [1]  0.80 13.09
  1. Sort the February rainfall values from wettest to driest. (2)
sort (DRIPDROP$Feb, decreasing = TRUE)
##   [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
range (DRIPDROP$Feb)
## [1]  0.76 13.35
  1. Compute the variance of the March rainfall values. (2)
var(DRIPDROP$Mar)
## [1] 7.41769
  1. What is the 95th percentile value of April rainfall? (2)
quantile(DRIPDROP$Apr, probs = c(.95))
##   95% 
## 10.21
  1. Create a time series graph of April rainfall. (4)
ggplot(DRIPDROP, aes(x = Year, y = Apr)) + geom_line() + ylab("April Rainfall (in)")