Instructions

This is your first homework assignment! It covers chapters 1 and 2 in QSS (Fogarty 2023) and Tutorial 2. To complete and submit this assignment, you’ll need to:

  1. Download the 701hw1.Rmd file from WebCampus and save it in the folder with your course project .Rproj file (we make this during the first session of the semester).

  2. Open your project and find the file in the “Files” tab in the lower-right corner of your RStudio Graphical User Interface (GUI, pronounced “gooey”).

  3. Open it up and scroll to the YAML header. Find the author: line and put your name where it says YOUR NAME HERE.

  4. Work your way through the file. Answer each question by adding/editing code in the code chunks and adding text outside of the code chunks as appropriate.

  5. When you are done click the “knit” button above the editor window. Check the quiz1.html file to ensure that your results and answers appear in the rendered document.

  6. Now, go back to the assignment page in WebCampus. Submit your quiz by uploading both your quiz1.Rmd file and your quiz1.html file and click to submit. You will be able to find both of these files in the same folder as your .Rproj file.


Question 1

Create an object called num_voters that contains the number 2750.

# type your code below:
num_voters <-2750

Question 2

Use c() to create a vector called district_names with the values “North”, “South”, and “Central”.

# type your code below:
district_names <- c("North", "South", "Central")

Question 3

Below you’ll find two vectors: votes_A and votes_B. Combine these vectors into a data frame called votes_df

votes_A <- c(500, 600, 700)
votes_B <- c(450, 580, 640)

# type your code below:
votes_A <- c(500, 600, 700)
votes_B <- c(450, 580, 640)
votes_df <- data.frame(votes_A, votes_B)

Question 4

Write a line of code to print your current working directory.

# type your code below:
print(getwd())
## [1] "D:/UNLV/Political Science/PSC 701 Research Design and Methods/R Project 1"

Question 5

Explain the difference between install.packages("dplyr") and library(dplyr).

install.packages(dplyr) command installs the dplyr package from CRAN onto my computer. It requires the package name to be enclosed in quotation marks, as it is used to specify the package to be installed.

library(dplyr) command loads the dplyr package into my current R session. It does not require the package name to be enclosed in quotation marks, as it refers to the package as an object already installed.

References

Fogarty, Brian J. 2023. Quantitative Social Science Data with R: An Introduction. SAGE.