ABC vs. CBS: Comparing Fictional Presidential Poll Data in R
# Assignment 3 - Fictional 2016 Presidential Poll Data
# Note: This data is made up and does NOT reflect real election results
# Candidate names
Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie")
# Poll results from ABC and CBS
ABC_poll <- c(4, 62, 51, 21, 2, 14, 15)
CBS_poll <- c(12, 75, 43, 19, 1, 21, 19)
# Combine data into a data frame
poll_data <- data.frame(Name, ABC_poll, CBS_poll)
# Add a column to compare differences between polls
poll_data$Difference <- CBS_poll - ABC_poll
# View the data
print(poll_data)
# Optional: Simple bar plot comparison
barplot(
t(as.matrix(poll_data[, c("ABC_poll", "CBS_poll")])),
beside = TRUE,
names.arg = poll_data$Name,
col = c("gray70", "gray40"),
legend.text = c("ABC Poll", "CBS Poll"),
main = "Fictional 2016 Presidential Poll Results",
ylab = "Poll Percentage"
)
For this assignment, I created a fictional dataset based on the 2016 presidential election to compare polling results from two different sources: ABC and CBS. The dataset includes several candidates and their corresponding poll percentages from each source. Even though the data is made up, it still shows how different polling organizations can report noticeably different results for the same candidates. For example, CBS consistently reports higher support for some candidates like Donald and Hillary, while ABC shows stronger results for others such as Ted. This highlights how polling outcomes can vary depending on methodology, sample size, or question wording. Using vectors in R made it easy to store and compare these values, and combining them into a data frame helped organize the data clearly. This exercise reinforced how R is designed to handle structured data efficiently, which aligns with the ideas discussed in The Art of R Programming, Chapters 3–5, where Matloff emphasizes R’s strength in vector-based operations and clean data organization.
Comments
Post a Comment