R:如何内的重命名一个数据帧的循环? [英] R: how to rename a dataframe within a for loop?

查看:236
本文介绍了R:如何内的重命名一个数据帧的循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要单独运行几个国家的API下载功能。我的变量是我从Excel列表读取字符串。每个观察由三个字母国家标识符标识( codeS [1,1] )。理想情况下,我想做到这一点:

  codeS = read.xls(data.xlsx)为(ⅰ在1:50){
codeS [1,1] = Quandl(C(的toString(codeS [I,2])的toString(codeS [我,3]),的toString(codeS [我,4 ])),​​倒塌=年度)
}

显然, codeS [1,1] = ... 不起作用。有一个简单的解决这个问题。性能不是一个大问题。感谢您的帮助。


解决方案

  codeS = read.xls(data.xlsx)为(ⅰ在1:50){
分配(codeS [1,1],Quandl(C(的toString(codeS [I,2])的toString(codeS [我,3]),的toString(codeS [我4)),倒塌=年))
}

试试。

I have to run an API download function for several countries separately. My variables are strings that I read in from an Excel-list. Each observation is identified by a three letter country identifier(codes[i,1]). Ideally, I would want to do this:

codes = read.xls("data.xlsx")

for(i in 1:50) {
codes[i,1] = Quandl(c(toString(codes[i,2]),toString(codes[i,3]),toString(codes[i,4])), collapse="annual")
}

obviously, codes[i,1] = ... doesn't work. Is there a simple solution to this problem. Performance isn't a major concern. Thanks for your help.

解决方案

codes = read.xls("data.xlsx")

for(i in 1:50) {
assign(codes[i,1], Quandl(c(toString(codes[i,2]),toString(codes[i,3]),toString(codes[i,4])), collapse="annual"))
}

Try that.

这篇关于R:如何内的重命名一个数据帧的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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