When given the myMean expression, the intended effect is to calculate the mean of a vector or object. Instead, an error message appears as such:
The issue with this line of code is that it makes assumptions about certain meanings and behaviors within the function. An example of this issue is that R does not recognize the function as computing an input, because the sole use of it in its current state is to calculate an unknown about the vector "assignment2". While the vector does contain a series of numbers, the function cannot properly run because the instructions are incorrect within the function itself. The existing code reads as follows:myMean <- function(assignment2)/length(assignment2)
{
return(sum(assignment2)/length(assignment2))
}
Which essentially "double-dips" in the intention of the code and produces a run error. Instead, the code should drop the latter part of the function directive (/length(assignment2)) and run normally.
This code returns an answer of 19.25, which can be confirmed using the mean() function and determining that these answers are consistent.
No comments:
Post a Comment