Skip to main content

Week 2 Assignment - myMean

 

     My assignment is to evaluate the unction myMean. The assignment contains the following data: 6, 18, 14, 22, 27, 17, 22, 20, 22 

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


  •  This line of code assigns the set of values in brackets to the variable Assignment 2, creating a vector. This variable could be set to a different name if I wanted to set it as "boing"

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


  • This line of code sets myMean as a function that can run assinment2 numbers and then also divides the sum of assinmehents2's values and the amount of numbers in it.

 

 

The result is [1] 18.66667

     

    In conclusion, it is making a shorthand for a longer expression by allowing you to refer to it like this: myMean(assignment2).


Comments