Module 2. Assignment

> assignment2<- c(6,18,14,22,27,17,22,20,22)
> myMean <- function(assignment2) {return(sum(assignment2)/length(assignment2))}
> myMean(assignment2)
[1] 18.66667

The function of assignment2 is to hold the numbers as a container so that later on,
it can be easily accessed, like in this example, when finding the mean. First,
assignment2 is created to group all the data numbers as a vector that will later be
used in the myMean function. To calculate the average, the function myMean uses
assignment2 to add the numbers using sum(assignment2), then counts how many
numbers are in assignment2 using length(assignment2). After that, the sum of
assignment2 is divided by how many numbers there are in assignment2. Which then gets
the mean of assignment2.


Comments