This function downloads the requested information using the World Bank API
wb_data( indicator, country = "countries_only", start_date, end_date, return_wide = TRUE, mrv, mrnev, cache, freq, gapfill = FALSE, date_as_class_date = FALSE, lang )
indicator | Character vector of indicator codes. These codes correspond
to the |
---|---|
country | Character vector of country, region, or special value codes for the
locations you want to return data for. Permissible values can be found in the
countries tibble in wb_cachelist or by running
|
start_date | Numeric or character. If numeric it must be in |
end_date | Numeric or character. If numeric it must be in |
return_wide | Logical. If |
mrv | Numeric. The number of Most Recent Values to return. A replacement
of |
mrnev | Numeric. The number of Most Recent Non Empty Values to return. A replacement
of |
cache | List of tibbles returned from |
freq | Character String. For fetching quarterly ("Q"), monthly("M") or yearly ("Y") values. Useful for querying high frequency data. |
gapfill | Logical. If |
date_as_class_date | Logical. If |
lang | Language in which to return the results. If |
a tibble of all available requested data.
obs_status
columnIndicates the observation status for location, indicator and date combination.
For example "F"
in the response indicates that the observation status for
that data point is "forecast".
# gdp for all countries for all available dates df_gdp <- wb_data("NY.GDP.MKTP.CD") # Brazilian gdp for all available dates df_brazil <- wb_data("NY.GDP.MKTP.CD", country = "br") # Brazilian gdp for 2006 df_brazil_1 <- wb_data("NY.GDP.MKTP.CD", country = "brazil", start_date = 2006) # Brazilian gdp for 2006-2010 df_brazil_2 <- wb_data("NY.GDP.MKTP.CD", country = "BRA", start_date = 2006, end_date = 2010) # Population, GDP, Unemployment Rate, Birth Rate (per 1000 people) my_indicators <- c("SP.POP.TOTL", "NY.GDP.MKTP.CD", "SL.UEM.TOTL.ZS", "SP.DYN.CBRT.IN") df <- wb_data(my_indicators) # you pass multiple country ids of different types # Albania (iso2c), Georgia (iso3c), and Mongolia my_countries <- c("AL", "Geo", "mongolia") df <- wb_data(my_indicators, country = my_countries, start_date = 2005, end_date = 2007) # same data as above, but in long format df_long <- wb_data(my_indicators, country = my_countries, start_date = 2005, end_date = 2007, return_wide = FALSE) # regional population totals # regions correspond to the region column in wb_cachelist$countries df_region <- wb_data("SP.POP.TOTL", country = "regions_only", start_date = 2010, end_date = 2014) # a specific region df_world <- wb_data("SP.POP.TOTL", country = "world", start_date = 2010, end_date = 2014) # if the indicator is part of a named vector the name will be the column name my_indicators <- c("pop" = "SP.POP.TOTL", "gdp" = "NY.GDP.MKTP.CD", "unemployment_rate" = "SL.UEM.TOTL.ZS", "birth_rate" = "SP.DYN.CBRT.IN") df_names <- wb_data(my_indicators, country = "world", start_date = 2010, end_date = 2014) # custom names are ignored if returning in long format df_names_long <- wb_data(my_indicators, country = "world", start_date = 2010, end_date = 2014, return_wide = FALSE) # same as above but in Bulgarian # note that not all indicators have translations for all languages df_names_long_bg <- wb_data(my_indicators, country = "world", start_date = 2010, end_date = 2014, return_wide = FALSE, lang = "bg")