On 29/12/2014 10:32 AM, Gerrit Draisma wrote:
> Just a curiosity question:
>
> In the documentation for the nlm procedure
> a find this example of defining a function
> with a gradient attribute:
> -----------
> f <- function(x, a)
> {
> res <- sum((x-a)^2)
> attr(res, "gradient") <- 2*(x-a)
> res
> }
> -----------
> I get the gradient with
> attr(f(3,2),"gradient")
> but how do I get the function value it self?
value <- f(3,2)
gradient <- attr(value, "gradient")
Duncan Murdoch
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.