In R Programming Basic Building Blocks: Functions, you are asked to return the last element of the vector c(4, 8, 0) using an anonymous function. When using the expression x[-1], we return the last two elements, yet the module evaluates this as correct, as shown below.
| 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[-1]}, c(8, 4, 0))
[1] 4 0
| You got it!
In R Programming Basic Building Blocks: Functions, you are asked to return the last element of the vector
c(4, 8, 0)
using an anonymous function. When using the expressionx[-1]
, we return the last two elements, yet the module evaluates this as correct, as shown below.