R Basics: Review worksheet

Political Analysis II
R Basics: Review worksheet
Michaelmas 2015
In the labs for Political Analysis II, we will pick up where left off in using R for data analysis.
This worksheet offers suggestions for refreshing your memory about how R and RStudio work.
1. Last year’s labs
Look through last year’s labs (they’re still on WebLearn) and refresh your memory about what we learned.
2. Tutorials in swirl
The package swirl offers interactive tutorials you can try within RStudio.
To install a package, go to the “Tools” drop-down menu and choose “Install packages. . . ”. Choose swirl.
Follow the directions from the swirl package. We suggest trying the following lessons:
1. Basic Building Blocks
4. Vectors
7. Matrices and Data Frames
12. Looking at Data
15. Basic Graphics
3. Other resources:
These websites provide additional tutorials and useful materials on R:
•
•
•
•
•
https://www.rstudio.com/resources/training/online-learning/#R
https://www.coursera.org/course/rprog
https://www.r-project.org/mail.html
http://www.statmethods.net
http://stackoverflow.com
4. Homework
If you haven’t done so already, download and install RStudio on your home computer or laptop.
Here are some tasks to make sure you have some of the basics down:
•
1. Create a vector called x that contains the numbers 1 to 50
•
2. Create a logical vector y that takes the value TRUE if x is smaller than 25
•
3. Type data() in the console to see a list of built-in datasets. Type data(datasetname) to load
one of them that sounds interesting, and answer these questions about the dataset:
1
– What are the variable names?
– What do the data look like? (Try dim(), str(), head().)
– Use the lm() command to run a regression of one variable on the other, and use summary() to
store the output. What does it mean?
2