Module # 3 data.frame
Code Repository: https://github.com/rayhankhan-svg/r-programming-assignments/blob/main/README.md
R Code:
# Create vectors
Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie")
ABC <- c(4, 62, 51, 21, 2, 14, 15)
CBS <- c(12, 75, 43, 19, 1, 21, 19)
# Create data frame
poll_results <- data.frame(Name, ABC, CBS)
# View data frame
poll_results
# Compare polls
poll_results$Difference <- poll_results$CBS - poll_results$ABC
poll_results
Output:
> # Compare polls
> poll_results$Difference <- poll_results$CBS - poll_results$ABC
> poll_results
Name ABC CBS Difference
1 Jeb 4 12 8
2 Donald 62 75 13
3 Ted 51 43 -8
4 Marco 21 19 -2
5 Carly 2 1 -1
6 Hillary 14 21 7
7 Bernie 15 19 4
>
Explanation:
I used fictional 2016 presidential polling data from two sources, ABC and CBS, to generate a data frame in R for this assignment. The data frame made it simple to view and compare several variables within a single structure by organizing candidate names and the poll results that corresponded to them. After comparing the data, I noticed differences in polling figures for several candidates between ABC and CBS. Results can vary depending on the source, as evidenced by the fact that certain candidates received more support in one poll than in another. These discrepancies were evident and simple to examine thanks to the use of a data frame. This fictional dataset was used to practice working with data frames and comparing variables in R.
Comments
Post a Comment