vectors Using functions Getting help 2) Data and projects in R- Studio Creating an R project Organizing/cleaning data Importing/exporting Data 3) Pizza! 4) Intro to Plotting Reproducible plots Basic plotting Building complex plots by small steps 5) A la Carte (time permitting): Programming (loops, conditionals & functions) Intro to Simulation Q & A
is command-driven • R will not tell you what to do, nor guide you through the steps of an analysis or method. • R will do all the calculations for you, and it will do exactly what you tell it (not necessarily what you want). • R has the flexibility and power to do exactly what you want, exactly how you want it done.
2 + 16 x 24 – 56 / (2+1) – 457 Bonus – calculate: The area of a circle with radius 5cm? The hypotenuse of triangle ABC with: • Angle ABC=90⁰ , Angle ACB=45⁰ • Side AB=5cm
R • images and other graphics made using R • a demonstration of linear modelling & GLMs • a list of available demos demo(graphics) demo(image) demo(lm.glm) demo() R is a show-off For even more demos, use: demo(package = .packages(all.available = TRUE))
assignment operator: <- assign the value on the right to the name on the left A <- 10 B <- 10*10 A_log <- log(A) B.seq <- 1:B Object names can be be (almost) anything you choose. They can include: Letters a-z, A-Z (case sensitive) Numbers 0-9 Periods . Underscores _ Should begin with a letter
is a vector • Think of a vector as a list of related values (data) • A single value is an 'atomic vector' (vector of length 1) [1] 2 1:10 index (item number) Value (result) [1] 1 2 3 4 5 6 7 8 9 10
object • To use a function (call), the command must be structured properly, following the "grammar rules" of the R language (syntax) log( 8 , base = 2 )
object • To use a function (call), the command must be structured properly, following the "grammar rules" of the R language (syntax) log( 8 , base = 2 ) Function name
object • To use a function (call), the command must be structured properly, following the "grammar rules" of the R language (syntax) log( 8 , base = 2 ) Function name No space Parentheses
object • To use a function (call), the command must be structured properly, following the "grammar rules" of the R language (syntax) log( 8 , base = 2 ) Function name No space Parentheses Argument 2 Arguments are separated by a Comma Argument 1
structure of the object names of items in the object attributes of the object summary statistics plot of all variable combinations data(CO2) head(CO2) str(CO2) names(CO2) attributes(CO2) summary(CO2) plot(CO2) Data Frames
by its index or name (if it has one) CO2$Treatment Indexing CO2[1:6,3] Object name Rows (dim. 1) columns (dim. 2) Object name Column operator Column name
CO2[sample(nrow(CO2), 10),] available named columns "Treatment" column all rows, column 3 row 3, all columns rows 1-6, all columns rows 1-6, column 3 elements 1-6 of Treatment rows where conc > 100 rows where Treatment == “chilled" 10 random rows
base functions in R, you can install additional packages to do specialized statistics and plotting. • Currently, the CRAN package repository features 4276 available packages. • http://cran.r-project.org/web/packages/