GOVT 8002 Shared Working Book
Benjamin Reese
1 Introduction
1.1 Purpose of This Site
The goal of this site is to have a place where you can look for examples of code. Think of this site as a log of all of the topics we cover in class and in lab sessions. I will make updates throughout the semester as we cover more advanced material. I hope this proves to be a helpful and beneficial resource and offer an easier to access format than the Google Doc.
Let me know if any of this code doesn’t run correctly or if you have any questions or issues!
1.2 Loading Data
The easiest way to load data into R and ensure you have the correct file path is to create a folder on your computer for each assignment and place the datasets directly into that folder.
Create a folder on your computer for each new analysis
Download your Data and move the file to your newly created folder
Then open RStudio
Click the project button in the top right corner
Click new project
Click existing directory
Click browse and find the folder that you created
Click create project
Once your new project opens, click the blank page with a green plus sign icon in the top left corner under the file option
Click R script to open a new script
You should also be able to see your data file in the bottom right window of RStudio, click the file and follow the options depending on the file type
Once your data is imported into R, the code that R automatically ran will be in the console window on the bottom left, copy and paste it to your fresh R script
- For example, in Lab 1, my code looked like:
read_excel("Data/USstates.xlsx")
Run this copy and pasted line of code whenever you open the R Project and you will never have to worry about complicated file pathing commands
I recommend using the assignment operator
<-
to give your dataset a short and simple name likedf
,dta
, or, if you are working with multiple datasets, name each something short and descriptive