alpha 2 codes in r

# Install and load the 'countrycode' package
install.packages("countrycode")
library(countrycode)

# Create a vector of country names
countries <- c("United States", "Canada", "United Kingdom", "Germany", "France")

# Use the countrycode() function to get alpha-2 codes
alpha2_codes <- countrycode(sourcevar = countries, origin = "country.name", destination = "iso2c")

# Display the result
print(alpha2_codes)