Editing Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 1
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 23: | Line 23: | ||
** logical: TRUE or FALSE (all caps) | ** logical: TRUE or FALSE (all caps) | ||
* functions: contains parentheses right after the variable name | * functions: contains parentheses right after the variable name | ||
** functions take some input (called an argument) and provide some output (called the output or something the return value | ** functions take some input (called an argument) and provide some output (called the output or something the return value) | ||
** there are many built in functions including: | ** there are many built in functions including: | ||
*** sqrt() | *** sqrt() | ||
Line 34: | Line 31: | ||
*** ls() | *** ls() | ||
*** check your reference card for many, many more | *** check your reference card for many, many more | ||
* vectors: you can think of a vector as like a list of things that are all the same | * vectors: you can think of a vector as like a list of things that are all the same time (lists, which will come to letter, actually refer to lists of things that might be of different types!) | ||
** in R, all variables are vectors! although many have just one thing in them! that's why it prints out [1] next to every numbers | ** in R, all variables are vectors! although many have just one thing in them! that's why it prints out [1] next to every numbers | ||
** you can make vectors with a special function: c(), like ages <- c(36, 4, 35) | ** you can make vectors with a special function: c(), like ages <- c(36, 4, 35) | ||
Line 51: | Line 48: | ||
*** some functions return a single item: sum(); mean(); sd(); median(); var(); length() | *** some functions return a single item: sum(); mean(); sd(); median(); var(); length() | ||
*** some return vectors: sort(); head(); range(); | *** some return vectors: sort(); head(); range(); | ||
*** | *** table() | ||
* more advanced variables types: | |||
** factors: for categorical data | |||
*** make with factor("mako", "mika", "mako") | |||
*** you can create factors from characters with as.factor() | |||
** also think about: dates with POSIXct(), ordered() — really just a type of factor for ordinal data | |||
* using logical vectors to index and recode data: | * using logical vectors to index and recode data: | ||
** comparison operators will return logical variables: rivers > 300; rivers < 300; rivers <= 320; rivers == 210; rivers != 210 | ** comparison operators will return logical variables: rivers > 300; rivers < 300; rivers <= 320; rivers == 210; rivers != 210 | ||
Line 59: | Line 61: | ||
** boxplot() — boxplots | ** boxplot() — boxplots | ||
** hist() — draw histograms | ** hist() — draw histograms | ||
* | ** density() — density plots | ||
* | * installing new pacakges and loading new datasets: | ||
* installing new | |||
** install.packages("UsingR") | ** install.packages("UsingR") | ||
** install.packages("openintro") | ** install.packages("openintro") | ||
*** library(UsingR) no quotes! | *** library(UsingR) no quotes! | ||