Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

r - Access odd-named object returned by getSymbols

I'm downloading data from Yahoo using quantmod:

> getSymbols("HNZ-A.TO")
[1] "HNZ-A.TO"
Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  downloaded length 70893 != reported length 200

The file shows up in my R workspace. The data is there and I can use edit to see the object, but I can't use the object. For example:

> head(HNZ-A.TO)
Error in head(HNZ - A.TO) : object 'HNZ' not found

What can I do to use this object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...