Getting Started with Data Frames in RStudio
When running the made-up data for the 2016 elections, I get the following error: "Error: unexpected input in "Name <- c("Jeb", “". After fixing the quotations we get another error: Error: unexpected symbol in "ABC political". After some troubleshooting, adding a comma that was missing, and fixing the names, I replaced the spaces with underscores. We have the following working code.
Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie") ABC_political_poll_results <- c( 4, 62, 51, 21, 2, 14, 15) CBS_political_poll_results <- c(12, 75, 43, 19, 1, 21, 19)
We can create a data frame to make visualizing the data easier using the following code.
polls_df <- data.frame( Name, ABC = ABC_political_poll_results, CBS = CBS_political_poll_results ) polls_df
We use the data. frame function to create a data frame with the given data sets, and then we call the data frame using polls_df, in which the data frame is stored, to see the data frame we created.
Name ABC CBS
1 Jeb 4 12
2 Donald 62 75
3 Ted 51 43
4 Marco 21 19
5 Carly 2 1
6 Hillary 14 21
7 Bernie 15 19
We can see that CBS shows higher polls towards Jeb, Donald, Hillary and Bernie. While ABC shows higher polls towards Ted, Marco and Carly.
Comments
Post a Comment