1 Statistics 517 Computing in Statistics © Fall 2004 Don Edwards and the University of South Carolina
2 Course Goals lR (=Splus) programming lSAS programming (DATA step) Syllabus l lRead it carefully!
3 A Typical Class lDiscuss previous coding exercise (10 min) lCoding discussion and demonstration (25-40 min) lAssign coding exercise lTime spent on exercises is “built in” to class time
4 Learning R lDon Edward’s notes lSupplemental exercises lMany other R resources available online
5 Basics of R, Chapters lIntro to R lObjects, Modes, Assignments lGetting Help
6 1. R: An Introduction lShareware version of S ( Splus) lVersion for Windows lSteep learning curve (case sensitive, cryptic help and error messages, data import and export)
7 1. R: An Introduction lStarting and quitting lObject oriented lVectors, factors, matrices, data frames, lists, functions lR object names are flexible lBe careful of built-in R names lDon’t let objects accumulate
8 2.1 Vectors lStrings of data elements of the same mode lMajor modes: numeric, character, logical lExamples from R data sets
9 2.1 Vectors lComponent extraction lAssignments (beware copying over variables!) lObject attributes (e.g. names) llength(), c(), “:”, seq() functions lNo shorthand for increments in “:” statement lFunctions can be nested
Factors lDefines groups in data (looks like a character vector, but no quotes) lLevels lCoercing to a character vector lOther coercion functions
Matrices lTwo-dimensinal array; columns have same mode (usually numeric) lAttributes: dim and dimnames lCaution about length() lExtracting a single element, or an entire row or column
Data Frames lR’s standard “data set” lTwo-dimensional array but columns may have different modes lAttributes: names, row.names lReferencing columns with $ lConversion of character vectors to factor objects by data.frame()
Lists lGlued-together strings of diverse objects lOutput of many R functions lE.g., attributes of any object lExtraction with [[ ]] lExtraction with $