Introduction and orientation

Jacob M. Montgomery
Washington University in St. Louis
Department of Politcal Science

2020

Introduction

Introductions

Orientation

Class discussion

Dramatic reading of the syllabus

1.1 What the …. ?

You can install R from: http://cran.r-project.org/bin/



But you should go ahead and also install Rstudio: https://rstudio.com/

1.2 The working environment for R/RStudio

Now make a new script and save it to an appropriate directory. Add the following, save, and run.

print("Hello world")
## [1] "Hello world"


Highlight the line and hit command-R (in a Mac) to run without menus.

1.3: Big picture orientation

1.4: R as a calculator

5+4 # Addition
## [1] 9
6-3  #Subtraction
## [1] 3
34 / 6 # Division
## [1] 5.666667
5 * 3 # Multiplication
## [1] 15
5^4 # Exponents
## [1] 625
625^(1/4) # More exponents
## [1] 5
11%%2 # modular arithmatic (11 mod 2)
## [1] 1
31 %/% 7 # The integer part of a fraction
## [1] 4

R comes with a number of constants pr-stored that you can use

6.25 # numbers
pi # And a few others
NA # Missing value
NULL # Nothing.
0/0 # NaN means "Not a number"
1/0 # Inf means infinity

R follows the order of operations (Please Excuse My Dear Aunt Sally). What will these evaluate to?

2*(3-4)+2
2*(3-4)+2*(4 + 3)^(1/3)

1.4: Objects and named storage

What if we wanted to calculate the % of eligible voters who turnout in the 06 elections in Alaska. (Data source: http://www.electproject.org/2006g)

turnout.ak<-238307/496387 # Turnout divided by voting age population
turnout.ak 
## [1] 0.4800831

Named storage also lets you handle each piece separately

total.votes.ak <-  238307
voting.age.population.ak <- 496387
turnout.ak <-total.votes.ak/voting.age.population.ak
turnout.ak
## [1] 0.4800831