提取函数结果 [英] Extract the results of a function

查看:46
本文介绍了提取函数结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下功能要最小化:

I have the following function that is to be minimized:

calloptim <- function( under,strike, rf, ttoe,par) {(-(under*par[1]
  -strike*exp(-rf*ttoe)*par[2]))^2}

我创建以下对象:

res<- nlminb(c(1,1), calloptim, under= 90, strike = 100, rf =0.05, ttoe=3)

res

$par
[1] 0.9771973 1.0218072

$objective
[1] 3.412923e-16

$convergence
[1] 1

$iterations
[1] 2

$evaluations
function gradient 
      34        4 

$message
[1] "false convergence (8)"

这很好,但是现在我想获取估计值$ par并将其放入向量中,以便将其用于其他计算.

This is fine but now I want to grab to $par estimate values and put them in a vector so I can use them for other calculations.

如何隔离和保存对象结果的仅一部分?

How do you isolate and save only parts of the result of an object?

推荐答案

以下内容大致相同:

res$par
res["par"]
res[1]
res[[1]]

查看帮助页面以获取?Extract 的详细信息.我经常发现查看对象的 str()有助于查找从中获取内容的位置,例如,要提取的对象的名称或它在您所在对象中的数字位置看着(在这种情况下为1).

Look at the help page for ?Extract for details. I often find looking at the str() of the object helpful when trying to find where to grab things from, i.e. either the name to of the object to extract or it's numerical location within the object you're looking at (1 in this case).

这篇关于提取函数结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆