Hi, I have a structure, which is the result of a function How can I access the elements in the gradient?> dput(test1)structure(-1.17782911684913, gradient = structure(c(-0.0571065371783791, -0.144708170683529), .Dim = 1:2, .Dimnames = list(NULL, c("x1", "x2"))))> test1[[1]][1] -1.177829> test1[1] -1.177829 attr(,"gradient") x1 x2 [1,] -0.05710654 -0.1447082> test1["gradient"][1] NA Thanks, Miao [[alternative HTML version deleted]]
Hi Miao, Try attributes(test1)[[1]] HTH, Jorge.- On Tue, Jun 11, 2013 at 3:49 PM, jpm miao <miaojpm@gmail.com> wrote:> Hi, > > I have a structure, which is the result of a function > How can I access the elements in the gradient? > > > dput(test1) > structure(-1.17782911684913, gradient = structure(c(-0.0571065371783791, > -0.144708170683529), .Dim = 1:2, .Dimnames = list(NULL, c("x1", > "x2")))) > > test1[[1]] > [1] -1.177829 > > test1 > [1] -1.177829 > attr(,"gradient") > x1 x2 > [1,] -0.05710654 -0.1447082 > > test1["gradient"] > [1] NA > > > Thanks, > > Miao > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]
Hello, Already asked and answered here: http://stackoverflow.com/questions/4034436/extract-the-gradient-from-the-deriv-command Regards, Pascal 2013/6/11 jpm miao <miaojpm@gmail.com>> Hi, > > I have a structure, which is the result of a function > How can I access the elements in the gradient? > > > dput(test1) > structure(-1.17782911684913, gradient = structure(c(-0.0571065371783791, > -0.144708170683529), .Dim = 1:2, .Dimnames = list(NULL, c("x1", > "x2")))) > > test1[[1]] > [1] -1.177829 > > test1 > [1] -1.177829 > attr(,"gradient") > x1 x2 > [1,] -0.05710654 -0.1447082 > > test1["gradient"] > [1] NA > > > Thanks, > > Miao > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]
Seemingly Similar Threads
- Why can't R understand if(num!=NA)?
- Definition of "lag" is opposite in ts and xts objects!
- How can I tabulate time series data (in RStudio or any other R editor)?
- How can I access an element of a string?
- How to print the frequency table (produced by the command "table" to Excel