do.call()出错:未使用的参数

时间:2013-07-10 09:51:33

标签: r quantmod

可重复的代码:

op <- par(no.readonly = TRUE)
Sys.setenv(TZ = 'UTC')

# *********************************
# 1. Installing packages
# *********************************

install.packages('quantmod')

# *********************************
# 2. Loading packages
# *********************************

require(compiler)
require(quantmod)

# *********************************
# 3. Downloading and preparing data
# *********************************

env <- new.env()
Symbols <- c('SPY', 'QQQ', 'XLF', 'GLD')
getSymbols(Symbols = Symbols, env = env, from = '1950-01-01')
args <- eapply(env = env, FUN = function(x){na.omit(merge(OpCl(x)))})
do.call(what = function(x){x}, args = args)

最后一个命令返回

Error in (function (x)  : 
  unused arguments (GLD = c(-0.00112536574386668, 0.00651831872330866, 0.00446927374301676, -0.00289661319073087, 0.00267082127754281, 0.000883977900552502, 0.00665188470066513, -0.0055102490632577, 0.00220848056537104, -0.0131723380900108, 0.0124333925399644, -0.00484688257325394, -0.00419426048565119, 0.00479452054794516, 0.000685714285714401, 0.00161401890707857, 0.00687915615684465, -0.00479890310786113, -0.00249433106575958, -0.00704705614912482, 0.00591850671522876, 0.000225580870742315, 0.00203942895989107, 
-0.00407239819004523, 0.00226398007697526, 0.00428990742831337, -0.00112561909049991, -0.00591985428051012, 0.00758620689655176, -0.00114025085518821, 0.000930665425779686, -0.00140186915887841, -0.00187134502923969, -0.00776836158192085, -0.00593965312425759, -0.000952607763753277, 0, 0.00188146754468477, 0.00495399858457191, 0.00308129888599207, 0.00236854571293232, -0.00914419695193436, 0.00308641975308643, 0.00992438563327047, 0.00070191857744506, -0.006818716200

我需要在类似矩阵的对象中强制args,这是一个列表。

1 个答案:

答案 0 :(得分:2)

由于你有xts个对象,我想你需要这样的东西:

  do.call(merge,args)

这将为4个符号创建单个时间序列:

 tail(do.call(merge,args))
                  OpCl.x      OpCl.x.1      OpCl.x.2     OpCl.x.3
2013-07-01  9.921627e-03 -0.0040837162 -0.0005574913 0.0006201166
2013-07-02 -1.063128e-02  0.0005122951  0.0008370536 0.0005585899
2013-07-03  3.314002e-04  0.0036082474  0.0076944600 0.0049850449
2013-07-05  8.468835e-05  0.0066023362  0.0019326339 0.0033852404
2013-07-08  3.526744e-03  0.0010025063 -0.0039758706 0.0005492494
2013-07-09 -1.820589e-03  0.0024888004  0.0015072623 0.0009092011