Problem Set # 1

Olivia Williams

date()
## [1] "Tue Sep 11 15:00:34 2012"

Due Date: September 13, 2012
Total Points: 30

1 The following values are the annual number hurricanes that have hit the United States since 1990. Follow instructions and answer questions by typing the appropriate 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. (2)

Hur=c(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? (2)

length(Hur)

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

sum(Hur)

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

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

N=seq(0,25)

b. What is the length of this vector? (2)

length(N)

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

M=(N-mean(N))

3 Suppose you keep track of your mileage each time you fill up. 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. (2)

miles=c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)

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

f=diff(miles)

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

max(f)
min(f)
mean(f)

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

a. “a”, “a”, “a”, “a” (2)

rep("a", 4)

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

seq(1,100, by=2)

c. 1, 1, 1, 2, 2, 2, 3, 3, 3 (2)

 rep(c(1,2,3), c(3, 3,3))

d. 1, 1, 1, 2, 2, 3 (2)

rep(c(1,2,3), c(3, 2,1))

e. 1, 2, 3, 4, 5, 4, 3, 2, 1 (3) Hint: Use the c() function.

c(seq(1,5),seq(4,1))