## 12. Appendix 1 ## 12.1 R Packages for Windows ## 12.2 Contributed Documents and Published Literature ## 12.3 Data Sets Referred to in these Notes ## 12.4 Answers to Selected Exercises ## Section 1.6 ## 1. plot(distance~stretch,data=elasticband) ## 2. (ii), (iii), (iv) plot(snow.cover ~ year, data = snow) hist(snow$snow.cover) hist(log(snow$snow.cover)) ## Section 2.7 ## 1. The value of answer is (a) 12, (b) 22, (c) 600. ## 2. prod(c(10,3:5)) ## 3(i) bigsum <- 0; for (i in 1:100) {bigsum <- bigsum+i }; bigsum ## 3(ii) sum(1:100) ## 4(i) bigprod <- 1; for (i in 1:50) {bigprod <- bigprod*i }; bigprod ## 4(ii) prod(1:50) ## 5. radius <- 3:20; volume <- 4*pi*radius^3/3 sphere.data <- data.frame(radius=radius, volume=volume) ## 6. sapply(tinting, is.factor) sapply(tinting[, 4:6], levels) sapply(tinting[, 4:6], is.ordered) ## Section 3.9 ## 2. par(mfrow = c(1,2)) plot(Animals$body, Animals$brain, pch=1, xlab="Body weight (kg)",ylab="Brain weight (g)") plot(log(Animals$body),log(Animals$brain),pch=1, xlab="Body weight (kg)", ylab="Brain weight (g)", axes=F) brainaxis <- 10^seq(-1,4) bodyaxis <-10^seq(-2,4) axis(1, at=log(bodyaxis), lab=bodyaxis) axis(2, at=log(brainaxis), lab=brainaxis) box() identify(log(Animals$body), log(Animals$brain), labels=row.names(Animals)) ## Section 7.9 ## 1. x <- seq(101,112) or x <- 101:112 ## 2. rep(c(4,6,3),4) ## 3. c(rep(4,8),rep(6,7),rep(3,9)) or rep(c(4,6,3),c(8,7,9)) mat64 <- matrix(c(rep(4,8),rep(6,7),rep(3,9)), nrow=6, ncol=4) ## 4. rep(seq(1,9),seq(1,9)) or rep(1:9, 1:9) ## 6. (a) Use summary(airquality) to get this information. (b) airquality[airquality$Ozone == max(airquality$Ozone),] (c) airquality$Wind[airquality$Ozone > quantile(airquality$Ozone, .75)] ## 7. mean(snow$snow.cover[seq(2,10,2)]) mean(snow$snow.cover[seq(1,9,2)]) ## 9. s summary(attitude); summary(cpus) ## 10. mtcars6<-mtcars[mtcars$cyl==6,] ## 11. Cars93[Cars93$Type=="Small"|Cars93$Type=="Sporty",]