Subset and return countries given a specified characters to search
Arguments
- char
character to search for
- full.list
whether to return only name of country or full list
See also
[countryStartsWith()] for country search starting with specified characters, and [countryHas()] for countries that contain specified characters.
Examples
# task 1: get only names of countries that end with "A" or "a"
# note that the search in case-insensitive
countryEndsWith("A", full.list = FALSE)
#> [1] "Albania" "Algeria" "Andorra"
#> [4] "Angola" "Antigua and Barbuda" "Argentina"
#> [7] "Anguilla" "Armenia" "Austria"
#> [10] "Australia" "Bolivia" "Bosnia and Herzegovina"
#> [13] "Botswana" "Bulgaria" "Cambodia"
#> [16] "Canada" "China" "Colombia"
#> [19] "Costa Rica" "Croatia" "Cuba"
#> [22] "Dominica" "Equatorial Guinea" "Eritrea"
#> [25] "Estonia" "Ethiopia" "Gambia"
#> [28] "Georgia" "Ghana" "Grenada"
#> [31] "Guatemala" "Guinea" "Guyana"
#> [34] "India" "Indonesia" "Jamaica"
#> [37] "Kenya" "Latvia" "Liberia"
#> [40] "Libya" "Lithuania" "Malaysia"
#> [43] "Malta" "Mauritania" "Moldova"
#> [46] "Mongolia" "Namibia" "Nicaragua"
#> [49] "Nigeria" "North Korea" "North Macedonia"
#> [52] "Panama" "Romania" "Russia"
#> [55] "Rwanda" "Saint Helena" "Saint Lucia"
#> [58] "Saudi Arabia" "Serbia" "Slovakia"
#> [61] "Slovenia" "Somalia" "South Africa"
#> [64] "South Korea" "Sri Lanka" "Syria"
#> [67] "Tanzania" "Tunisia" "Uganda"
#> [70] "Venezuela" "Zambia"
# task 2: get only names of countries that end with "No" or "no"
countryEndsWith("no", full.list = FALSE)
#> [1] "San Marino"
# task 3: repeat task 2, but return full list for each country
countryEndsWith("no")
#> $`1`
#> ID name currency symbol isocode fractionalunity officiallanguage
#> 151 10151 San Marino Euro \200 EUR Cent Italian
#> population2023 callingcode continent capital
#> 151 33847 378 Europe San Marino
#>