Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was wondering, *for which countries is the proportion of Phone line users to population greater than or equal to that of the United States?*

This is what I inputted below, but the list of countries seem too great.

countries=Last/@Take[Reverse[Sort[{CountryData[#,"PhoneLines"], #} & /@CountryData[]]], All]

Someone suggested I use "Select", but I have difficulties wording it.

share|improve this question

1 Answer 1

up vote 3 down vote accepted
Select[CountryData[], CountryData[#, "PhoneLines"]/CountryData[#, "Population"] >= 
   CountryData["USA", "PhoneLines"] / CountryData["USA", "Population"] &]

Gives:

{"Barbados", "Bermuda", "BritishVirginIslands", "Canada", 
"CaymanIslands", "Cyprus", "FalklandIslands", "France", "Germany", 
"Gibraltar", "Greece", "Guernsey", "HongKong", "Iceland", 
"IsleOfMan", "Jersey", "Liechtenstein", "Luxembourg", "Malta", 
"Monaco", "Montenegro", "Niue", "NorfolkIsland", 
"SaintPierreMiquelon", "SanMarino", "Slovenia", "Sweden", 
"Switzerland", "Taiwan", "UnitedKingdom", "UnitedStates", 
"UnitedStatesVirginIslands", "VaticanCity"}

EDIT

You can make CountryData Listable and use good 'ol Pick

SetAttributes[CountryData, Listable];    
Pick[CountryData[], CountryData[CountryData[], "PhoneLines"] / CountryData[CountryData[], 
"Population"], _?(# >= CountryData["USA", "PhoneLines"] / CountryData["USA", "Population"] &)]
share|improve this answer
    
+1 I sometimes hate Mma's verbosity cd = CountryData; pl = "PhoneLines"; po = "Population"; Select[cd[], cd[#, pl]/cd[#, po] >= cd["USA", pl]/cd["USA", po] &] –  belisarius Oct 24 '13 at 18:52
    
@Belisarius. I totally agree. –  RunnyKine Oct 24 '13 at 18:53
2  
Almost golfed cd = CountryData; r@x_ := cd[x, "PhoneLines"]/cd[x, "Population"]; Select[cd[], r@# >= r@"USA" &] –  belisarius Oct 24 '13 at 18:57
    
@Belisarius. Nice! I like it much better. –  RunnyKine Oct 24 '13 at 19:00
1  

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.