[R] ISO3 code to 7 continents names

David Winsemius dwinsemius at comcast.net
Sat Sep 9 00:54:22 CEST 2017


> On Sep 7, 2017, at 12:56 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> 
> 
>> On Sep 7, 2017, at 12:21 PM, Miluji Sb <milujisb at gmail.com> wrote:
>> 
>> df is a data frame consisting of one variable (iso3 codes) such as
>> 
>> USA
>> RUS
>> ARG
>> BGD
>> ITA
>> FRA
>> 
>> 
>> Some of these iso3 codes are repeated and I would like the corresponding continent name, the countrycode package does not seem to distinguish between North and South America. Thanks.
> 
> Well it does actually: There are two different region codes:
> 
> First load the package that has countryExData. I'm presuming this is:
> 
> library(rworldmap)
> 
>> table(countryExData$EPI_regions)
> 
>   Central and Eastern Europ    East Asia and the Pacific                       Europe 
>                          19                           18                           24 
>   Latin America and Caribbe Middle East and North Africa                North America 
>                          24                           19                            2 
>                  South Asia           Sub-Saharan Africa 
>                           5                           38 
>> table(countryExData$GEO_subregion)
> 
>      Arabian Peninsula Australia + New Zealand               Caribbean 
>                      5                       2                       5 
>         Central Africa            Central Asia          Central Europe 
>                      6                       5                      16 
>         Eastern Africa          Eastern Europe                 Mashriq 
>                      7                       7                       4 
>           Meso America           North America          Northeast Asia 
>                      8                       2                       5 
>        Northern Africa           South America              South Asia 
>                      5                      11                       6 
>        South East Asia           South Pacific         Southern Africa 
>                      8                       3                      10 
>         Western Africa          Western Europe    Western Indian Ocean 
>                     13                      19                       2 
> 
> Then create the described dataframe:
> 
> df<- data.frame(iso3=scan(what="") )
> 1: USA
> 2: RUS
> 3: ARG
> 4: BGD
> 5: ITA
> 6: FRA
> 7: 
> Read 6 items
> 
> 
>> region <- merge(countryExData,df,by.x='ISO3V10',by.y='iso3')$EPI_regions
> 
>> region
> [1] "Latin America and Caribbe" "South Asia"                "Europe"                   
> [4] "Europe"                    "Central and Eastern Europ" "North America"    

Looking at that one might wonder about the degree of success. The ordering of the matched results was not determined by the order in the second df-object:

 merge(countryExData,df,by.x='ISO3V10',by.y='iso3')
  ISO3V10       Country               EPI_regions  GEO_subregion Population2005
1     ARG     Argentina Latin America and Caribbe  South America        38747.2
2     BGD    Bangladesh                South Asia     South Asia       141822.3
3     FRA        France                    Europe Western Europe        60495.5
4     ITA         Italy                    Europe Western Europe        58092.7
5     RUS        Russia Central and Eastern Europ Eastern Europe       143201.6
6     USA United States             North America  North America       298212.9
  GDP_capita.MRYA landlock   landarea density  EPI ENVHEALTH ECOSYSTEM ENVHEALTH.1 AIR_E
1         13652.4        0  2736296.0     1.3 81.8      91.1      72.5        91.1  87.3
2          1916.2        0   136248.1    95.0 58.0      53.6      62.4        53.6  95.7
3         28876.5        0   547106.7    17.9 87.8      99.4      76.2        99.4  95.9
snipped

-- 
David.


> -- 
> David.
> 
>> 
>> Sincerely,
>> 
>> Milu
>> 
>> On Thu, Sep 7, 2017 at 9:00 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>> 
>>> On Sep 7, 2017, at 11:36 AM, Miluji Sb <milujisb at gmail.com> wrote:
>>> 
>>> Dear all.
>>> 
>>> Is it possible to convert.identify iso3 country names to the seven
>>> continent names?
>>> 
>>> # Asia, Africa, Antarctica, Australia, Europe, South America, and North
>>> America,
>>> 
>>> I have tried the following:
>>> 
>>> ###
>>> region <- merge(countryExData,df,by.x='ISO3V10',by.y='iso3')
>>> 
>>> where df is the name of my dataset with iso3 the identification variable
>>> but there seems to be a a lot of missing values.
>> 
>> Please provide a sufficient amount of the dataframe named `df` to allow a properly tested response.
>> 
>>> 
>>>      [[alternative HTML version deleted]]
>> 
>> And do read the Posting Guide. This is a plain text mailing list.
>>> 
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> David Winsemius
>> Alameda, CA, USA
>> 
>> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>> 
>> 
>> 
>> 
>> 
>> 
> 
> David Winsemius
> Alameda, CA, USA
> 
> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law



More information about the R-help mailing list