Skip to contents

With specified country name or names, get the associated population

Usage

populationOf

Format

An object of class list of length 193.

Value

a list containing all countries and their corresponding population

Examples

# view the searchable countries, return first 6
head(names(populationOf))
#> [1] "afghanistan"         "albania"             "algeria"            
#> [4] "andorra"             "angola"              "antigua and barbuda"

#task 0: check if the population of japan is included
#should be all in lower case
grep("japan",names(populationOf), value = TRUE)
#> [1] "japan"

#task 1: check the population of nigeria
populationOf$nigeria
#> [1] 216783400

#task 2: check the population of united states
populationOf$`united states`
#> [1] 335340000


#task 3: check population of multiple countries
populationOf[c("slovenia","romania","malaysia")]
#> $slovenia
#> [1] 2117674
#> 
#> $romania
#> [1] 19051562
#> 
#> $malaysia
#> [1] 33200000
#> 

#task 4: what if the population is not available
populationOf[c("randomcountry","mexico","luxembourg")]
#> $<NA>
#> NULL
#> 
#> $mexico
#> [1] 129035733
#> 
#> $luxembourg
#> [1] 660809
#>