Module # 2 Introduction to basic R functions and Data Structures

Module # 2 Introduction to basic R functions and Data Structures


The function myMean determines the mean (average) of a given numeric vector. Assignment2 is the vector that was utilized in this instance. The only parameter required by the myMean function is assignment2. Using sum(assignment2), the function determines the sum of the components in assignment 2. Using / length(assignment2), it then divides the total by the number of components in assignment 2. The function's output is the outcome of this division, which is returned. The mean of the numeric vector assignment2 is calculated by the myMean function. The mean of the values in the assignment2 vector can be obtained by using this function with the argument myMean(assignment2).

The function ran through RStudio is as follows:

assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
myMean <- function(assignment2) {
  return(sum(assignment2) / length(assignment2))
}

result <- myMean(assignment2)
print(result)


Output:

[1] 19.25

Comments

Popular posts from this blog

LIS 4370: Module # 10 Building your own R package

LIS 4317 Final Project: Fuel Economy Data from the U.S Dept. of Energy

LIS 4317: Module # 10 assignment