Problem Set # 2

Guang Xing

date()
## [1] "Tue Sep 25 15:29:25 2012"

Due Date: September 27, 2012
Total Points: 30

1 The following ten observations, taken during the years 1970-1979, are on October snow cover for Eurasia in units of millions of square kilometers. Follow the instructions and answer questions by typing the appropriate R commands.

Year Snow
1970 6.5
1971 12.0
1972 14.9
1973 10.0
1974 10.7
1975 7.9
1976 21.9
1977 12.5
1978 14.5
1979 9.2

a. Create a data frame from these data. (2)

year = 1970:1979
snow = c(6.5, 12, 14.9, 10, 10.7, 7.9, 21.9, 12.5, 14.5, 9.2)
EUsnow = data.frame(Year = year, Snow = snow)
EUsnow
##    Year Snow
## 1  1970  6.5
## 2  1971 12.0
## 3  1972 14.9
## 4  1973 10.0
## 5  1974 10.7
## 6  1975  7.9
## 7  1976 21.9
## 8  1977 12.5
## 9  1978 14.5
## 10 1979  9.2

b. What are the mean and median snow cover over this decade? (2)

paste("The mean is", mean(EUsnow$Snow))
## [1] "The mean is 12.01"
paste("The median is", median(EUsnow$Snow))
## [1] "The median is 11.35"

c. What is the standard deviation of the snow cover over this decade? (2)

sd(EUsnow$Snow)  # The standard deviation
## [1] 4.391

d. How many Octobers had snow cover greater than 10 million km\( ^2 \)? (2)

sum(EUsnow$Snow > 10)
## [1] 6

2 The data set rivers contains the lengths (miles) of 141 major rivers in North America.
a. What proportion of the rivers are shorter than 500 miles long? (2)

data(rivers)
sum(rivers < 500)/length(rivers)
## [1] 0.5816

b. What proportion of the rivers are shorter than the mean length? (2)

sum(rivers < mean(rivers))/length(rivers)
## [1] 0.6667

c. What is the 75th percentile river length? (2)


quantile(rivers, probs = 0.75)  # the 75th percentile river length
## 75% 
## 680 

d. What is the interquartile range in river length? (2)

IQR(rivers)
## [1] 370

3 Consider the SSN.txt file on Blackboard. The file contains monthly sunspot numbers for since 1851.
a. Read the data into R to create a data frame. (4)

setwd("C:/Users/Guang/Desktop/quantitative_geography/Data_Sets")
Sunsdata = read.table("SSN.txt", header = TRUE)  # sunspot data

b. Create a histogram of the September sunspot numbers. (2)

hist(Sunsdata$Sep)

plot of chunk unnamed-chunk-11


c. Create a scatter plot placing the June sunspot numbers on the horizontal axis and September sunspot numbers on the vertical axis. (4)

plot(Sunsdata$Jun, Sunsdata$Sep, xlab = "June sunspot numbers", ylab = "September sunspot numbers")

plot of chunk unnamed-chunk-12

d. Use the grammar of graphics syntax to create a plot showing the September sunspot numbers on the vertical axis and the year on the horizontal axis. (4)


plot(Sunsdata$Year, Sunsdata$Sep, ylab = "September sunspot numbers", xlab = "Year", 
    type = "l")

plot of chunk unnamed-chunk-13