R: Using an anonymous function to return the last element of a vector [closed]
Assuming that evaluate is a function that takes a function and some data and applies that function to the data… evaluate <- function(func, dat){ func(dat) } then the following should work… evaluate(function(x){x[length(x)]}, dat=c(8,4,0)) in this case x[length(x)] will give you the last element of the vector x.