Need help with error message on R Studio

Hi
I am defining a vector called countrylist as follows

library(wbstats)
countrylist <- c("Liberia" = LBR, "Mauritius" = MUS, "Namibia" = NAM, "Rwanda" = RWA)
Error: object 'LBR' not found

I get this error message. I don't think I did something wrong in defining that vector?

By the way, I am trying to access the World Bank database and got all the codes from the World Bank's Website.

Can anyone help?

Thank you

Valerier

Hi @vcheongtook

when defining a vector, if you don't use quotations around a word R will assume you want to reference a variable with that name.
In your case LBR is not quoted so R searches for a variable named LBR. Since it didn't find one it throws the error.

So

countrylist <- c("Liberia" = "LBR", "Mauritius" = "MUS", "Namibia" = "NAM", "Rwanda" = "RWA")

will resolve the error.

Full code

library(wbstats)

countrylist <- c("Liberia" = "LBR", "Mauritius" = "MUS", "Namibia" = "NAM", "Rwanda" = "RWA")

# from the help page of the function wb_data
# 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(indicator = my_indicators,
                 country = countrylist)
1 Like

Hi @vedoa
Thank you loads for your help. Much appreciated.

Valerie

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.