1. Administrative stuff. Adding, prerequisites, etc. The syllabus. The good and bad things about this course, the book, and my teaching. Grammar vs. vocabulary. Read ch. 1-4. 2. R Cookbook. Downloading and installing R. It's free and works on any major platform. Relatively easy to install. See p2. If you have problems, you might use the computers in the labs to do the first assignment. They already have R. It's a good idea to use a Text editor, like Alpha (or the default R text editor in the GUI version of R, or MS Word, or any other text editor), and copy and paste commands into R. To get Alpha, see http://alphatcl.sourceforge.net/wiki/pmwiki.php/Software/AlphaX . Table 1-1. Up arrow and down arrow are useful. ## anything after a number sign is a comment. 2 + 3 ## arithmetic 2 * 4 2 - 5 2 / 7 sqrt(7) 7^2 ## exponents 7^(1/2) 7^1/2 ## without parentheses, ## exponents are done before multiplication and division x = 2 ## assignment x x <- 3 x x == 3 if(x == 3) y = 4 y (x == 3) * 3.4 x = c(1,4,8) ## a vector x ## notice how it prints x out. y = c(1,4,7) x == y x = 1:50 x print(x) Print(x) ## R cares about capitalization. mean(x) q() Most people use x = 3 these days, though "=" can also be a logical operator. pi e exp(1) exp(2) help() and example() are useful. help(exp) help(mean) help(sqrt) help(adf.test) help(adf.test) said "no documentation for 'adf.test'". The book says "The problem is that the function's package is not currently loaded." library() ## list of downloaded packages install.packages("spatial") ## only need to do this once (per computer) library(spatial) ## need this every R session when you need spatial functions help.search("adf.test") library(tseries) help(adf.test) Print, p23, is fairly self explanatory. c means combine. x = c("fee", "fie", "foe", "fum") print("The zero occurs at", 2*pi, "radians.") yields an error: unimplemented type. The book solves this using repeated calls to print(). cat() is useful. Use \n for a new line. cat("The zero occurs at",2*pi,"radians.\n The end.") print() works with many different objects, but cat() doesn't like lists. See p25. On the top of p24, the book says print(matrix(c(1,2,3,4), 2, 2)) This makes a 2 by 2 matrix with the elements of the vector [1,2,3,4] read in column by column. To read them in by row, do x = matrix(c(1,2,3,4), 2, 2, byrow=T) print(x) The top of p27 gives a simple example of a function. f <- function(n,p) sqrt(p*(1-p)/n) f(4,.1) p27, ls() is useful. When you load a package, though, the functions in the package don't appear in ls(). p30, see mean, median, etc. mean(x) median(x) sd(x) Note that sd goes column by column, but by default, mean and median act on all elements together as one vector. We will see how to take column or row means individually later, using apply().