Loop R with Quandl as optional

て烟熏妆下的殇ゞ 提交于 2019-12-13 09:16:39

问题


I'm starting programming R. I use Quandl to download historical futures data (GCG1975, GCJ1975, GCM1975, GCQ1975, GCV1975, GCZ1975, GCG1976, GCJ1976, GCM1976, ..., GCZ2016).

Month codes:

G J M Q V Z

Years:

1975:2016

I want to download it all, but I don't want to tape it all, so I think I want a function that downloads a year with all the months and then the next year again all the months. As an example, to download the first year:

require(Quandl)
Quandl("CME/GCG1975")

Any tip about the function or functions that are needed to this question is useful for me. Also if someone knows how to do it in Python is fine.

Thanks,

RTA


回答1:


This answer assumes reading of the earlier question and comments so is not "code only".

 qt = expand.grid(Month=c("G","J","M","Q","V"), Year=1975:2016) 
 query_names_vec <- apply(qt, 1, 
                       function(x) paste0("CME/GC", paste0( x, collapse="") ) )

> head( query_names_vec )
[1] "CME/GCG1975" "CME/GCJ1975" "CME/GCM1975" "CME/GCQ1975"
[5] "CME/GCV1975" "CME/GCG1976"


来源:https://stackoverflow.com/questions/40953151/loop-r-with-quandl-as-optional

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