Module # 2 Assignment
Evaluate myMean Function Use the vector: assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22) Consider this function: myMean <- function(assignment2) { return(sum(assignment) / length(someData)) } assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22) myMean <- function(assignment2) { return(sum(assignment) / length(someData)) } myMean(assignment2) Error in sum(assignment) : object 'assignment' not found The function fails due to incorrect variable names inside the function body . The function argument is named assignment2 Inside the function, the variables assignment and someData are used These variables do not exist within the function or the global environment Corrected Version of myMean() myMean <- function ( assignment2 ) { sum ( assignment2 ) / length ( assignment2 ) } Testing the Corrected Function myMean ( assignment2 ) Correct Output [ 1 ] 19.25 Reflection This exercise helped reinforc...