Skip to content

Evaluating a Function

For this assignment, we were tasked to evaluate the function myMean and describe it’s function.

The function is as follows:

myMean <- function(assignment2) {return(sum(assignment2)/length(assignment2))}

with the dataset:

assignment2<- c(6,18,14,22,27,17,22,20,22)

Result

The result of this function in RGUI is:

> myMean(assignment2)
[1] 18.66667

Explanation

The myMean function is used to find the mean of the data set. It does so by summing the elements of the array (in this case assignment2) and dividing it by the arrays length. It can be demonstrated simply like so:

sum / length