Using swirl
"Programming E" exercise 9.
55% progress on the exercise and trying to use the function:
evaluate <- function(func, dat){
func(dat)
}
Keep getting the error message:
Error in func(dat) : could not find function "func"
Using swirl
"Programming E" exercise 9.
55% progress on the exercise and trying to use the function:
evaluate <- function(func, dat){
func(dat)
}
Keep getting the error message:
Error in func(dat) : could not find function "func"
I assume you're getting this error message because you aren't supplying a function to the func
argument in evaluate
. Using your function:
evaluate <- function(func, dat) {
func(dat)
}
We can reproduce the error message by giving the func
argument anything except a function:
evaluate(1, 2)
Error in func(dat) : could not find function "func"
However, if we supply a function, evaluate
should work:
evaluate(function(x) {x + 1}, c(1, 2))
# [1] 2 3
Or to make it more explicit:
evaluate(func = function(x) {x + 1},
dat = c(1, 2))
# [1] 2 3
I was getting this error in swirl as well. If we are indeed talking about the same error, this is the context and the code producing the error:
| Let's take your new evaluate() function for a spin! Use evaluate to find the
| standard deviation of the vector c(1.4, 3.6, 7.9, 8.8).
> evaluate(c(1.4,3.6,7.9,8.8))
Error in func(dat) : could not find function "func"
The not so obvious error to someone who is still learning is that this isn't supplying the function to use. Since "func" isn't an actual function by itself, we need to supply the function, standard deviation, to use for the evaluate function. The following is what I used in this exercise, sd being the standard deviation function, to get the desired results and to proceed with the lesson:
> evaluate(sd,c(1.4,3.6,7.9,8.8))
[1] 3.514138
| Perseverance, that's the answer.
This supplies the function sd() for "func" from our evaluate() function, and the c() vector for "dat".