Posts

Showing posts from January, 2024

Module # 3 Data.frame

  Exploring Fictional 2016 Presidential Election Poll Results In this blog post, we delve into a fictional dataset based on the 2016 presidential election. It's essential to note that this data is entirely fabricated and does not reflect the actual events of the election. The purpose is to explore the dynamics of political polls and the insights we can gain from them. The Candidates: Let's begin by introducing the candidates included in our fictional poll: - Jeb - Donald - Ted - Marco - Carly - Hillary - Bernie Poll Results: We have two sources for our poll data: ABC and CBS. The poll results for each candidate from these sources are as follows: ```R # Creating the data Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie") ABC_poll_results <- c(4, 62, 51, 21, 2, 14, 15) CBS_poll_results <- c(12, 75, 43, 19, 1, 21, 19) ``` Visualizing the Data: Let's create visualizations to bet...

Introduction to Basic R functions and Data Structures

Introduction to Basic R functions and Data Structures  Firstly, let's understand the function: myMean <- function(assignment2) {    return(sum(assignment2)/length(assignment2))  } This function, myMean, takes a vector assignment2 as an argument. It calculates the mean (average) of the values in the vector using the formula: sum of values divided by the number of values. Now, let's evaluate the function with the provided data: assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22) result <- myMean(assignment2) print(result) This will output the mean of the assignment2 vector. Explanation: sum(assignment2) calculates the sum of all values in the vector. length(assignment2) gives the number of elements in the vector. The division of the sum by the length gives the mean.