Editing Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 1

From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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()
** another useful function to clean up our messes: rm() or remove()
** 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 type (lists, which will come to letter, actually refer to lists of things that might be of different types!)
* 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 console
** adding comments: lines that start with # (or anything after a #)
* installing new packages and loading new datasets:
** 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!
Second lecture on GitHub and saving files:
* creating/saving files
** creating saving R scripts in RStudio
** running things in the console (Ctrl-Enter)
** copying things from the console (and vice versa)
* github
** how version control, git, github works
*** working directors, the role of the github desktop client, and the github website!
*** just an interface between your working directory and the website
** walk through example of saving something and publishing it in github
* other sources of help:
* other sources of help:
** built in documentation
** built in documentation
** StackOverflow
** StackOverflow
** R reference card
** R reference card
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see CommunityData:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)