Assignment #3
In this assignment, I created a fictional dataset in R to represent polling results from two different news sources, ABC and CBS, during the 2016 presidential election. The dataset consisted of a vector of candidate names and two numeric vectors representing the poll results from each source. Although the data does not reflect the real election, the purpose of the assignment was to practice working with vectors and organizing them into a data frame, as discussed in Chapter 5 of The Art of R Programming.
After creating the vectors, I combined them into a data frame so the information could be viewed in a tabular format. This made it easier to compare the polling results across candidates and sources. I then added a new column to the data frame that calculated the difference between the CBS and ABC polls (CBS − ABC). The results showed that several candidates, including Jeb, Donald, Hillary, and Bernie, had higher values in the CBS poll, while others such as Ted, Marco, and Carly had higher values in the ABC poll. These differences demonstrate how two polling sources can report varying levels of support even when evaluating the same candidates.
Using simple indexing and built-in R functions, I identified that Donald had the highest polling results in both the ABC and CBS polls, while Carly had the lowest results in both sources. I also calculated the average poll values, which showed that the mean for CBS (27.14) was higher than the mean for ABC (24.14). Overall, this assignment reinforced how data frames, column access, and logical subsetting in R can be used to organize data and quickly extract meaningful comparisons between related datasets.
macauleywilson/r-programming-assignments


Comments
Post a Comment