Module # 3 Data.frame
Data.frame
> Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Berine")
>
> # Defining the ABC political poll results
>
> ABC_poll_results <- c(4, 62, 51, 21, 2, 14, 15)
>
> # Defining the CBS political poll results
>
> CBS_poll_results <- c(12, 75, 43, 19, 1, 21, 19)
>
> # Combine into a data frame
> poll_data <- data.frame(
+ Candidate = Name,
+ ABC = ABC_poll_results,
+ CBS = CBS_poll_results
+ )
>
> # Print the data frame
> print(poll_data)
Candidate 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 Berine 15 19
I worked with a dataset showing the results of a fictional 2016 presidential election poll. While setting it up, I encountered a few issues, like using curly quotes instead of straight quotes and forgetting a comma between "Marco" and "Carly." I also used spaces in variable names like ABC_poll_results, which caused errors in R. To fix this, I replaced the spaces with underscores, and the code worked fine after that. After resolving these issues, the data showed that Donald Trump led both the ABC and CBS polls by a wide margin. The process was simple, and once everything was in the data frame, I could start analyzing the poll results and compare the candidates' performances across the two polls.
Comments
Post a Comment