date()
## [1] "Wed Sep 18 14:24:13 2013"
Due Date: September 19, 2013 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 = c(1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979)
Snow = c(6.5, 12, 14.9, 10, 10.7, 7.9, 21.9, 12.5, 14.5, 9.2)
data.frame(Year, Snow)
## 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)
mean(Snow)
## [1] 12.01
median(Snow)
## [1] 11.35
c. What is the standard deviation of the snow cover over this decade? (2)
sd(Snow)
## [1] 4.391
d. How many Octobers had snow cover greater than 10 million km\( ^2 \)? (2)
which(Snow > 10)
## [1] 2 3 5 7 8 9
length(which(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)
which(rivers < 500)
## [1] 2 3 4 6 8 9 11 12 13 14 17 18 19 27 28 29 30
## [18] 33 34 35 36 37 39 41 42 43 46 47 48 49 51 52 53 54
## [35] 55 56 57 60 61 65 72 73 74 75 76 77 78 81 87 88 91
## [52] 92 93 94 95 96 97 100 102 103 104 105 106 107 108 110 111 112
## [69] 116 117 119 122 123 124 125 126 127 129 133 134 138 139
length(which(rivers < 500))
## [1] 82
length(which(rivers < 500))/length(rivers)
## [1] 0.5816
b. What proportion of the rivers are shorter than the mean length? (2)
mean(rivers)
## [1] 591.2
length(which(rivers < mean(rivers)))
## [1] 94
length(which(rivers < mean(rivers)))/length(rivers)
## [1] 0.6667
c. What is the 75th percentile river length? (2)
quantile(rivers, 0.75)
## 75%
## 680
d. What is the interquartile range in river length? (2)
IQR(rivers)
## [1] 370
3 Consider the SSN.txt file from http://myweb.fsu.edu/jelsner/data/SSN.txt. The file contains monthly sunspot numbers for since 1851.
a. Import the data into R. (4)
loc = "http://myweb.fsu.edu/jelsner/data/SSN.txt"
SSN = read.table(loc, header = TRUE)
b. Create a histogram of the September sunspot numbers. (2)
require(ggplot2)
## Loading required package: ggplot2
ggplot(SSN, aes(Sep)) + geom_histogram(fill = "black") + theme_bw()
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
c. Create a boxplot of the June sunspot numbers. Label the axis. (4)
boxplot(SSN$Jun, ylab = ("June Susnpot Numbers"))
d. Create a scatter plot placing the June sunspot numbers on the horizontal axis and September sunspot numbers on the vertical axis. Label the axes. (4)
require(ggplot2)
ggplot(SSN, aes(x = Jun, y = Sep)) + geom_point() + xlab("June Sunspot Numbers") +
ylab("September Sunspot Numbers") + theme_bw()