R语言如何调用世界银行数据来比较GDP
标签:
r语言世界银行数据数据分析it |
分类: DataScience |
调用世界银行数据主要是用到WDI包,直接读取数据。
WDI包简介:WDI(World Development Indicators (World Bank)):世界发展指标(世界银行),搜索、提取和格式化从来自世界银行的“世界发展指标”数据。
WDI使用说明
打开RGui或者RStudio,需要安装两个包WDI和ggplot2
> install.packages(c("WDI","ggplot2"),.Library)
用WDI包的WDI函数,将中国、俄罗斯、南非、印度、巴西这五国的GDP数据载入,时间为1990-2010年,在选择国家时需使用ISO-2标准的国家代码,数据指标是世界银行的特定编码,你可以通过WDIsearch("gdp")命令来得到所有GDP的编码。
> WDIsearch(string='gdp', field='N', indicator='NY.GDP.MKTP.KD.ZG')
Series.Code Series.Name
749 NY.GDP.MKTP.KD.ZG GDP growth (annual %)
......> DF[c(DF$country=="China"),]
> library(ggplot2)
> library(WDI)
>DF = WDI(country=c("CN","RU","BR","ZA","IN"),indicator="NY.GDP.MKTP.KD.ZG",start=1990, end=2010)
查看数据,只截取中国的GDP增长
country iso2c year NY.GDP.MKTP.KD.ZG
21 China CN 1990 3.8
20 China CN 1991 9.2
19 China CN 1992 14.2
18 China CN 1993 14.0
17 China CN 1994 13.1
16 China CN 1995 10.9
15 China CN 1996 10.0
14 China CN 1997 9.3
13 China CN 1998 7.8
12 China CN 1999 7.6
11 China CN 2000 8.4
10 China CN 2001 8.3
9 China CN 2002 
加载中…