> submit()
| Sourcing your script...
| Keep working like that and you'll get there!
|============================ | 56%
| 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(sd,c(1.4,3.6,7.9,8.8)) [1] 3.514138
| You're the best!
|============================= | 58%
| The idea of passing functions as arguments to other | functions is an important and fundamental concept in | programming.
...
|============================== | 60%
| You may be surprised to learn that you can pass a | function as an argument without first defining the passed | function. Functions that are not named are appropriately | known as anonymous functions.
...
|=============================== | 62%
| Let's use the evaluate function to explore how anonymous | functions work. For the first argument of the evaluate | function we're going to write a tiny function that fits | on one line. In the second argument we'll pass some data | to the tiny anonymous function in the first argument.
...
|================================ | 65%
| Type the following command and then we'll discuss how it | works: evaluate(function(x){x+1}, 6)
> evaluate(function(x){x+1},6) [1] 7
| That's the answer I was looking for.
|================================= | 67%
| The first argument is a tiny anonymous function that | takes one argument `x` and returns `x+1`. We passed the | number 6 into this function so the entire expression | evaluates to 7.
...
|================================== | 69%
| Try using evaluate() along with an anonymous function to | return the first element of the vector c(8, 4, 0). Your | anonymous function should only take one argument which | should be a variable `x`.
> evaluate(function(x){x[1]},c(8,4,0)) [1] 8
| Nice work!
|=================================== | 71%
| Now try using evaluate() along with an anonymous function | to return the last element of the vector c(8, 4, 0). Your | anonymous function should only take one argument which | should be a variable `x`.
> evaluate(function(x){x[length(x)]},c(8,4,0)) [1] 0
| Excellent job!
|==================================== | 73%
| For the rest of the course we're going to use the paste() | function frequently. Type ?paste so we can take a look at | the documentation for the paste function.
> ?paste
| You got it right!
|====================================== | 75%
| As you can see the first argument of paste() is `...` | which is referred to as an ellipsis or simply | dot-dot-dot. The ellipsis allows an indefinite number of | arguments to be passed into a function. In the case of | paste() any number of strings can be passed as arguments | and paste() will return all of the strings combined into | one string.
...
|======================================= | 77%
| Just to see how paste() works, type paste("Programming", | "is", "fun!")
> paste("Programming","is","fun!") [1] "Programming is fun!"
| Excellent job!
|======================================== | 79%
| Time to write our own modified version of paste().
...
|========================================= | 81%
| Make sure to save your script before you type submit().
|