Access odd-named object returned by getSymbols

爱⌒轻易说出口 提交于 2019-11-27 05:37:21

Use back-ticks or get.

HNZA.TO <- `HNZ-A.TO`
HNZA.TO <- get("HNZ-A.TO")

Or you could avoid this all-together by setting auto.assign=FALSE in your call to getSymbols.

HNZA.TO <- getSymbols("HNZ-A.TO", auto.assign=FALSE)

You might also want to adjust the column names, via:

colnames(HNZA.TO) <- make.names(colnames(HNZA.TO))

HNZ <- getSymbols('HNZ-A.TO', auto.assign=FALSE) per the help page for getSymbols.

Another alternative is to setSymbolLookup to tell getSymbols to use a different Symbol in the query.

> setSymbolLookup(HNZ=list(src="yahoo", name="HNZ-A.TO"))
> getSymbols("HNZ")
[1] "HNZ"

Ok, but so you cannot get the quotes. Maybe another solution could be:

HNZ<-read.csv("http://ichart.finance.yahoo.com/table.csv?s=HNZ-A.TO&ignore=.csv", stringsAsFactors=F)

head(HNZ)

The advantage is that it is still easy to get the columns you want easily.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!