Monday, January 30, 2023

 Hello Class,

In this assignment we were to calculate the mean of two polls for several candidates.  To do this (you may find my code here: https://github.com/Wellis11/assignment3 , I combined two concatenated lists of poll values into a data frame.  I then found the mean of each row of values (ABC and NBC polls).  I wanted to organize this by candidate, so I combined this new list of means with the list of candidate names into a new data frame.

I imagine there is a more efficient way of doing this.  I would liked to have found a way to create just a single data frame and calculate the mean of numerical components of rows and present the results headed by the candidate names.

Below is my code and output.

>Name = c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie")

>ABC_political = c(4, 62, 51, 21, 2, 14, 15)

>NBC_political = c(12, 75, 43, 19, 1, 21, 19)

>first.df = data.frame(ABC_political, NBC_political)

>first.df

>pollmean=(rowMeans(first.df))

>pollmean

>second.df = data.frame(Name, pollmean)

>second.df


No comments: