本文介绍了R:如何在 for 循环中重命名数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须分别为多个国家/地区运行 API 下载功能.我的变量是我从 Excel 列表中读入的字符串.每个观察值都由三个字母的国家标识符(codes[i,1]
)标识.理想情况下,我想这样做:
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")
}
显然,codes[i,1] = ...
不起作用.这个问题有没有简单的解决方案.性能不是主要问题.感谢您的帮助.
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"))
}
试试看.
这篇关于R:如何在 for 循环中重命名数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!