Posts

Showing posts from January, 2023

Obtaining mean from data frame and matrix

This is an explanation about the conversion of given values of data into data frame and matrix and obtaining mean from them. Name of the candidates outlined in the data frame is Jeb, Donald, Ted, Marco, Carly, Hillary and Bernie. Sources of the polls here are ABC and CBS. Data of the names and political results of both polls are added to the environment. > Name <- c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Berine") > ABC_political_poll_results <- c(4, 62, 51, 21, 2, 14, 15) > CBS_political_poll_results <- c(12, 75, 43, 19, 1, 21, 19) By applying ‘cbind’ to the values, merged data with all three columns of the values into data 'poll_results' is obtained. > poll_results<-cbind(Name,ABC_political_poll_results,CBS_political_poll_results) > poll_results      Name      ABC_political_poll_results CBS_political_poll_results [1,] "Jeb"     "4"        ...

Testing Functions in R

Today I have created a custom function to find the mean of a given data frame, I have also compared the results with the inbuild R function "mean".  Theoretically “A function is defined by an assignment of the form.   > name <- function (arg_1, arg_2, ...) expression This expression is used to calculate a value. Value of the expression is the value returned for the function”. (Venables et al., 2022) Using this expression and formula for the mean which is defined by the sum of the digits divided by the total number of digits, I understood that mean function can be expressed as myMean <- function(assignment2{return(sum(assignment2)/length(assignment2))} R usually has already existing functions in its programming language. For example, adding values to the environment and then calling for mean. Using command mean(assignment2) is enough to get the result. But, in case if R doesn't have inbuilt designated tasks, then it can be carried out by defining eve...
 This is my Git repository for my Introduction to "R programming course" at USF URL: https://github.com/VedaVangala/vedas-r-repo.git