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