我有这个问题对我没有意义。R在for循环中填充数据帧
TickerList <- c("NAB.AX", "WES.AX", "TLS.AX", "CSL.AX", "WPL.AX", "SUN.AX")
for (Ticker in TickerList)
{
tickerdata.w <- get.hist.quote(Ticker, start = "2000-01-01",compression = "w", quote = "AdjClose")
#This is to get Continuous Compounding Return
ticker.log.data <- log(lag(tickerdata.w)) - log(tickerdata.w)
#This should give the name of the ticker to the log data
#eg, the first one will end up with a NAB.AX
assign(Ticker, ticker.log.data)
#Now I want to get the first data into a dataframe.
#So I want MyData to hold the NAB.AX log data.
#I know the loop works but there is something wrong with assigning the ticker data to the dataframe.
if (Ticker == TickerList[1]) {
MyData = (Ticker)
#And now the rest are to be merged into the dataframe
} else {
MyData = merge(MyData, Ticker)
}
}
但是,它只是不起作用。唯一进入数据框的是名称,例如NAB.AX而不是数据。
任何指导将是最受欢迎的。
您的示例不可重现。什么是get.hist.quote?它住在什么包里? –
我不小心(可能是niavely)认为,当我将Ticker分配给data.frame时,Ticker将成为ticker.log.data。抛出一些打印后,我发现ticker.log.data在分配后仍然存在,我可以使用该data.frame在if循环中填充MyData。我希望这可以帮助未来的人。 – Stephen
对不起,get.hist.quote在库(tseries)中。 – Stephen