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 16: | Line 16: | ||
** saving numbers to variables: cups.of.flour <- 2 | ** saving numbers to variables: cups.of.flour <- 2 | ||
** special variables built in: pi (we'll see many more) | ** special variables built in: pi (we'll see many more) | ||
* types of variables | * types of variables | ||
** numeric: we've already seen, with or without the decimal point | ** numeric: we've already seen, with or without the decimal point | ||
** character: name <- "mako" (uses single or double quotes) | ** character: name <- "mako" (uses single or double quotes) | ||
** logical: TRUE or FALSE (all caps) | ** logical: TRUE or FALSE (all caps) | ||
* functions: contains | * functions: contains parens right after the variable name | ||
** there are many built in functions including: | ** there are many built in functions including: | ||
*** sqrt() | *** sqrt() | ||
Line 34: | Line 28: | ||
*** 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) | ||
** vectors can be of any type but they have to one type: c("mako", "mika") | ** vectors can be of any type but they have to one type: c("mako", "mika") | ||
** if you mix vectors together, they will be "coerced"(!) | ** if you mix vectors together, they will be "coerced"(!) | ||
** vectors can names for elements! we can set those with names(): | ** vectors can names for elements! we can set those with names(): | ||
*** names(ages) | *** names(ages) | ||
*** names(ages) <- c("mako", "atom", "mika") | *** names(ages) <- c("mako", "atom", "mika") | ||
** many functions are particularly useful on vectors with multiple elements: | ** many functions are particularly useful on vectors with multiple elements: | ||
*** | *** sum() | ||
*** | *** mean() | ||
*** | *** median() | ||
* | *** length() | ||
** | * 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! | ||