循环R与Quandl作为可选 [英] Loop R with Quandl as optional

查看:162
本文介绍了循环R与Quandl作为可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始编程R.我使用Quandl下载历史期货数据(GCG1975,GCJ1975,GCM1975,GCQ1975,GCV1975,GCZ1975,GCG1976,GCJ1976,GCM1976,...,GCZ2016) / code>。

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

月份代码:

我想要全部下载,但我不想磁带,所以我想我想要一个功能,下载一年,所有的月份,然后在明年再次下降一个月。例如,要下载第一年:

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

有关此问题所需的功能或功能的任何提示对我都很有用。另外,如果有人知道如何在Python中做到这一点。

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.

谢谢,

RTA

推荐答案

这个答案假设读取以前的问题和评论所以不是仅代码。

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"

这篇关于循环R与Quandl作为可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆