2015-10-16 65 views
0

一个非常简单的问题。 我试图创建for循环在这个不同的数据帧:R编程:如何在for循环中创建几个数据框架

for (i in seq_along(country_code)) { UrlRoot<-"http://climatedataapi.worldbank.org/climateweb/rest/v1/country/cru/tas/month/" fileUrl <- paste(UrlRoot,country_code[i],sep = "") get_tas <- fromJSON(fileUrl) climate_data <- rbind(climate_data,get_tas)

我的目标是创建每包含气候数据,我可以从API获得国家的数据帧。像:

AWA 

month data 

0  21 

1  21.3 

...  .... 

AFG 

0  19.5 

1  22.4 

...  .... 

但我不能将其他数据存储在不同的数据框中的国家的数据。这是我得到:

 month  data 
1  0 26.49174100 
2  1 26.67431300 
3  2 27.21926500 
4  3 27.64128500 
5  4 28.24770500 
6  5 28.43945000 
7  6 28.56605500 
8  7 28.79541400 
9  8 28.83853100 
10  9 28.36330200 
11  10 27.78715500 
12  11 27.09082600 
13  0 0.09617378 
14  1 2.24567600 
15  2 7.38042300 
16  3 13.16199500 
17  4 18.25324400 
18  5 23.07769600 
19  6 25.17552200 
20  7 23.81981300 

任何提示?非常感谢!!

回答

0

为什么不添加一列到climate_data的国家名称(climate_data$country <- i),然后查询相应的国家。

或使用assign(i, climate_data),它将climate_data的值赋值给名称为i的变量。