1

我的工作区中有许多大型对象, xts我试图通过使用cbind、甚至在循环中组合它们。目前,数据为分时数据,因篇幅原因无法粘贴到此处。但是,我想做的是:mergeapplyxts

cbind(AAPL.O, AMZN.O, BIDU.O, GLD.A, ...) -> all

通过使用以下名称粘贴cbind

stock1 <- c("AAPL.O", "AMZN.O", "BIDU.O", "GLD.A", ...) # names of xts objects

# However this only combines the names "AAPL.O" & "AMZN.O"
cbind(paste(stock1[1]), paste(stock1[2])) 

我也试过apply

apply(t(stock1), 2, cbind)

但它只组合了stock1. 我也尝试过使用:

merge(SPY.A, source [stock1])

但得到以下错误: Error in source[stock1] : object of type 'closure' is not subsettable

由于我不能把所有的刻度数据放在这里,我将提供一些代码来从网上下载数据getSymbols()

library(quantmod)

symbols <- c("AAPL", "AMZN", "BIDU", "GLD")

getSymbols(symbols)

#These will yield the same problem I am having
cbind(paste(symbols[1]),paste(symbols[2] ))  

apply(t(symbols), 2, cbind)

merge(AAPL, source [symbols])
4

1 回答 1

1

也许mget和的组合do.call对你有用,但如果没有一些样本输入和预期输出,就很难说。

一个例子:

## Some matrices to combine using `cbind`
M1 <- matrix(1:4, ncol = 2)
M2 <- matrix(5:8, ncol = 2)
M3 <- matrix(9:10, ncol = 1)

## Like your "stock1"
Get <- c("M1", "M2", "M3")

do.call(cbind, mget(Get))
#      [,1] [,2] [,3] [,4] [,5]
# [1,]    1    3    5    7    9
# [2,]    2    4    6    8   10
于 2014-07-03T07:23:15.350 回答