Re: [R] attribute and main value

2014-12-29 Thread Gerrit Draisma
Thanks Bill, That is what I was looking for. Gerrit On 12/29/2014 05:53 PM, William Dunlap wrote: as.vector(x) will return x without any attributes and structure(x, attrA=NULL, attrB=NULL) will return x without the named attributes. > z <- f(1:3, 4) > z [1] 14 attr(,"gradient")

Re: [R] attribute and main value

2014-12-29 Thread William Dunlap
as.vector(x) will return x without any attributes and structure(x, attrA=NULL, attrB=NULL) will return x without the named attributes. > z <- f(1:3, 4) > z [1] 14 attr(,"gradient") [1] -6 -4 -2 > as.vector(z) [1] 14 > structure(z, gradient=NULL) [1] 14 as.vector is a gen

Re: [R] attribute and main value

2014-12-29 Thread Gerrit Draisma
Thanks Duncan. But my question was how to extract simply the function value from value, without the gradient attribute? I see that things like value<2 give the right answer. I was curiosity. I found now that value[1] gives strips the attributes from value: -- > value [1] 1 attr(,"gradient")

Re: [R] attribute and main value

2014-12-29 Thread Duncan Murdoch
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(r

[R] attribute and main value

2014-12-29 Thread Gerrit Draisma
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