HERE ARE SOME GENERAL NOTES ON R FACILITIES Reading data from files: scan("file") Good for reading a vector of numbers read.table("file",head=F) Reads data with one case per line, returning a data frame read.table("file",head=T) Reads data in which the first line has the names of the variables as.matrix(df) Converts a data frame to a matrix Plotting: par(mfrow=c(1,2)) Put two plots on one page. pdf("file.pdf",width=w,height=h) Directs a plot to a PDF file, which plot(...) can then be viewed or printed with dev.off() acroread Debugging: options(warn=2) Have warnings treated as errors (so they're easier to debug) traceback() Right after an error, shows which function it occured in options(error=dump.frames) Allow use of the debugger after an error debugger() Start up the debugger, right after an error SPECIAL STUFF FOR ASSIGNMENT 1: m <- lm (y ~ X) Fit linear model for y with matrix of inputs X coef(m) Get the regression coefficients (including the intercept) for the model fit above order(v) Find the ordering of elements of v that would make them be in ascending order. as.vector(m) Useful for converting a 1-by-n or n-by-1 matrix to a plain vector %*% Does a matrix-by-matrix multiply, or a matrix-by-vector or vector-by-matrix multiply M[-i,] The matrix consisting of all rows of M EXCEPT row i (assuming i is positive).