# NOTE: These examples are wrapped in a "don't run" because these
# require an internet connection
# gdp for all countries for all available dates
if (FALSE) {
df_gdp <- wb_data("NY.GDP.MKTP.CD")
}
# Brazilian gdp for all available dates
if (FALSE) {
df_brazil <- wb_data("NY.GDP.MKTP.CD", country = "br")
}
# Brazilian gdp for 2006
if (FALSE) {
df_brazil_1 <- wb_data("NY.GDP.MKTP.CD", country = "brazil", start_date = 2006)
}
# Brazilian gdp for 2006-2010
if (FALSE) {
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)
if (FALSE) {
my_indicators <- c(
"SP.POP.TOTL",
"NY.GDP.MKTP.CD",
"SL.UEM.TOTL.ZS",
"SP.DYN.CBRT.IN"
)
}
if (FALSE) {
df <- wb_data(my_indicators)
}
# you pass multiple country ids of different types
# Albania (iso2c), Georgia (iso3c), and Mongolia
if (FALSE) {
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
if (FALSE) {
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
if (FALSE) {
df_region <- wb_data("SP.POP.TOTL",
country = "regions_only",
start_date = 2010, end_date = 2014
)
}
# a specific region
if (FALSE) {
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"
)
if (FALSE) {
df_names <- wb_data(my_indicators,
country = "world",
start_date = 2010, end_date = 2014
)
}
# custom names are ignored if returning in long format
if (FALSE) {
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
if (FALSE) {
df_names_long_bg <- wb_data(my_indicators,
country = "world",
start_date = 2010, end_date = 2014,
return_wide = FALSE, lang = "bg"
)
}
Run the code above in your browser using DataLab