Skip to contents

Subset and return countries given a specified characters to search

Usage

countryStartsWith(char, full.list = TRUE)

Arguments

char

character to search for

full.list

whether to return only name of country or full list

Value

country data list matching a specified character

See also

[countryEndsWith()] for country search ending in specified character, and [countryHas()] for countries that contain specified characters.

Examples

# task 1: get only names of countries that start with "A" or "a"
# note that the search in case-insensitive
countryStartsWith("A", full.list = FALSE)
#>  [1] "Afghanistan"         "Albania"             "Algeria"            
#>  [4] "Andorra"             "Angola"              "Antigua and Barbuda"
#>  [7] "Argentina"           "Anguilla"            "Armenia"            
#> [10] "Austria"             "Australia"           "Azerbaijan"         

# task 2: get only names of countries that start with "No" or "no"
countryStartsWith("no", full.list = FALSE)
#> [1] "North Korea"     "North Macedonia" "Norway"         

# task 3: repeat task 2, but return full list for each country
countryStartsWith("no")
#> $`1`
#>        ID        name         currency   symbol isocode fractionalunity
#> 132 10132 North Korea North Korean won <U+20A9>     KPW            Chon
#>     officiallanguage population2023 callingcode continent   capital
#> 132           Korean       25660000         850      Asia Pyongyang
#> 
#> $`2`
#>        ID            name         currency symbol isocode fractionalunity
#> 133 10133 North Macedonia Macedonian denar    DEN     MKD            Deni
#>         officiallanguage population2023 callingcode continent capital
#> 133 Macedonian, Albanian        1832696         389    Europe  Skopje
#> 
#> $`3`
#>        ID   name        currency symbol isocode fractionalunity
#> 134 10134 Norway Norwegian krone     kr     NOK             Øre
#>     officiallanguage population2023 callingcode continent capital
#> 134        Norwegian        5514042          47    Europe    Oslo
#>