Lab Assignment 2 February 1st In this assignment you will: - Review and practice basic syntax in R - Practice basic operations using vectors and functions Getting Started: In RStudio select FILE (or...

1 answer below »

Lab Assignment 2


February 1st


In this assignment you will:
- Review and practice basic syntax in R - Practice basic operations using vectors and functions


Getting Started:



  1. In RStudio select FILE (or use the + button) -> NEW FILE -> R Notebook

  2. In the YAML/header do the following:

    • Replace “R Notebook” with “Lab Assignment 2”

    • Add the following 2 lines immediately below title: “Lab Assignment 2”

      • author: “Your name here”

      • date: “The date when you create the file here”





  3. Save your file as YOURLASTNAME_Lab2 in the folder you created for this class in the last assignment

  4. In RStudio go to HELP -> CHEATSHEETS -> “R Markdown Reference Guide”. This will help you answer any R Markdown questions you may have.


Instructions:


Respond to each of the questions in your R Notebook file. When you are finished, make sure you have run all the code chunks. Then preview the document (do so along the way to check your progress) and upload the .Rmd file and the nb.html file to Canvas. Make sure you name your file using the following format: YOURLASTNAME_LabX.


For each question, include the question numberQuestion Xbefore inserting any code chunks or answering questions. You do not need to rewrite the question.




Question 1:After saving your notebook, insert a code chunk and print your current working directory by using the function getwd().




Question 2:In the table below are votes cast for both major party candidates in the 2016 recent presidential election for a random sample of states (every fifth alphabetically). Insert a code chunk that creates a vector of Trump votes. Name it something intuitive. Repeat for Clinton votes. Check your work by listing each vector.



































































State NameTrump Vote CountClinton Vote Count
Alabama1,318,255729,547
California4,483,8148,753,792
Florida4,617,8864,504,975
Indiana1,557,2861,033,126
Maine335,593357,735
Mississippi700,714485,131
New Hampshire345,790348,526
Ohio2,841,0062,394,169
South Carolina1,155,389855,373
Vermont95,369178,573
Wyoming174,41955,973



Question 3:Continuing to work with the 2016 election results, insert a code chunk that computes thepercentof the vote Clinton won in each state and assign them to a vector. Check your work by printing out the vector.




Question 4:Generate a vector that contains the state names and assign the results to Clinton’s percent of the vote (the vector you created in previous question) using thenames()function. Print Clinton’s vote percent.




Question 5:Insert a chunk of code that produces a new vector that gives the share of the vote won by Clinton in each state that she won (but no others) using the which() function. Print out the vector. In another codechunk, create another vector with the share of votes won by Clinton in each state that she won by manually selecting out those states using index c(). Print out the new vector.

Answered 1 days AfterFeb 14, 2021

Answer To: Lab Assignment 2 February 1st In this assignment you will: - Review and practice basic syntax in R -...

Mohd answered on Feb 16 2021
140 Votes
Lab Assignment 2
Lab Assignment 2
Question 1:
getwd()
## [1] "/cloud/project"
Question 2:
Stat
e_Name<-c("Alabama","California","Florida","Indiana","Maine","Mississippi","New Hampshire","Ohio","South Carolina","Vermont","Wyoming")
Trump_vote_count<-c(1318255,4483814,4617886,1557286,335593,700714,345790,2841006,1155389,95369,174419)
Clinton_vote_count<-c(729547,8753792,4504975,1033126,357735,485131,348526,2394169,855373,178573,55973)
State_Name
## [1] "Alabama" "California" "Florida" "Indiana"
## [5] "Maine" "Mississippi" "New...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here