This week I evaluated this code in R and GitHub:
assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
myMean <- function(assignment2) { return(sum(assignment)/length(someData))}
myMean
The code complied and ran as follows:
>assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22)
>myMean <- function(assignment2) { return(sum(assignment2)/length(someData))}
>myMean
function(assignment2) { return(sum(assignment2)/length(someData))}
The code runs with no errors but the function calls sum(assignment) not sum(assignment2) so the mean would not be of the data in the assignment2 vector. The function does not return the value of myMean, but rather returns a copy of the function. “someData” needs to be defined as a value (such as 12) or the length of assignment2 vector.
GitHub link: https://github.com/mslement/IntroRProgrammingSlement/blob/master/myMean