myMean Error and Correction
Using the following vector and function in RStudio, I ran myMean(assignment2). assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22) myMean <- function(assignment2) { return(sum(assignment) / length(someData)) } The output was "Error in myMean(assignment2) : object 'assignment' not found". The function fails because assignment and someData are not assigned variables. These objects do not exist, so trying to pass them to the function myMean(assignment2) results in an error. To correctly return the mean of assignment2, the myMean function needs the variable assignment2 to replace assignment and someData. Corrected version of myMean, which returns 19.25. myMean <- function(assignment2) { return(sum(assignment2) / length(assignment2)) }