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 26: | Line 26: | ||
*** some arguments are named (meaning that they have "foo=" or similar before them. mostly names are optional) | *** some arguments are named (meaning that they have "foo=" or similar before them. mostly names are optional) | ||
** the most important function: help() | ** the most important function: help() | ||
** there are many built in functions including: | ** there are many built in functions including: | ||
*** sqrt() | *** sqrt() | ||
Line 34: | Line 33: | ||
*** 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 52: | Line 51: | ||
*** some return vectors: sort(); head(); range(); | *** some return vectors: sort(); head(); range(); | ||
*** some functions return other things: table(); summary() | *** some functions return other things: table(); summary() | ||
* 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 63: | ||
** boxplot() — boxplots | ** boxplot() — boxplots | ||
** hist() — draw histograms | ** hist() — draw histograms | ||
** density() — density plots | |||
* creating/saving files | * creating/saving files | ||
** running things in the | ** adding comments: lines that start with # (or anything after a #) | ||
* installing new | ** copying things from the bottom | ||
** running things in the terminal | |||
* installing new pacakges and loading new datasets: | |||
** the simplest way is with load() | ** the simplest way is with load() | ||
** install.packages("UsingR") | ** install.packages("UsingR") | ||
** install.packages("openintro") | ** install.packages("openintro") | ||
*** library(UsingR) no quotes! | *** library(UsingR) no quotes! | ||
* other sources of help: | * other sources of help: | ||
** built in documentation | ** built in documentation | ||
** StackOverflow | ** StackOverflow | ||
** R reference card | ** R reference card |