Statistics 540 Computing in Statistics © Fall 2004 Don Edwards and the University of South Carolina
Course Goals Syllabus R (=Splus) programming SAS programming (DATA step) Syllabus Read it carefully!
Syllabus Read it carefully
A Typical Class Review previous coding exercise (10-20 min) Coding discussion and demonstration (40 min) Assign coding exercise Part of the time spent on exercises is “built in” to class time
Learning R Don Edward’s notes Supplemental exercises Many other R resources available online
Basics of R, Chapters 1-2.5 Intro to R Objects, Modes, Assignments Getting Help
1. R: An Introduction Shareware version of S (Splus) Version 3.4.1 (I have 2.15.2) for Windows; 3.4.1 (I have 3.2.4) for Mac Steep learning curve (case sensitive, cryptic help and error messages, data import and export) Download R yourself
1. R: An Introduction (cont) Starting and quitting Object oriented Vectors, factors, matrices, data frames, lists, functions R object names are flexible Be careful of built-in R names Don’t let objects accumulate Objects organized by types; types have common attributes and common treatment by functions.
2.1 Vectors Strings of data elements of the same mode Major modes: numeric, character, logical Examples from R data sets
2.1 Vectors (cont) Component extraction Assignments (beware copying over variables!) Object attributes (e.g. names) length(), c(), “:”, seq() functions No shorthand for increments in “:” statement Functions can be nested Component extraction is an odd name for this function. No warning if copying over! Discuss <- , = and _
2.2 Factors Defines groups in data (looks like a character vector, but no quotes) Levels Coercing to a character vector Other coercion functions The similarity to character vectors causes problems if you’re not wary. Factors are very useful in analysis.
2.3 Matrices Two-dimensional array; columns have same mode (usually numeric or logical) Attributes: dim and dimnames Caution about length() Extracting a single element, or an entire row or column
2.4 Data Frames R’s standard “data set” Two-dimensional array, but columns may have different modes Attributes: names, row.names Referencing columns with $ Conversion of character vectors to factor objects by data.frame() A data frame is also a list, to be discussed next.
2.5 Lists Glued-together strings of diverse objects Output of many R functions E.g., attributes of any object Extraction with [[ ]] Extraction with $