Skip to content

Instantly share code, notes, and snippets.

@amy17519
Created August 22, 2016 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amy17519/0284c70b8659c726160fa8e19cf19b6b to your computer and use it in GitHub Desktop.
Save amy17519/0284c70b8659c726160fa8e19cf19b6b to your computer and use it in GitHub Desktop.
user[which(is.na(user$Country)),3]<-'Undefined Country'
user$Country<-tolower(user$Country)
user$City<-tolower(user$City)
user$Country<-recode(user$Country,
"c('81250 r.o.c taiwan','台灣','taiwan( r.o.c)','taichung','roc')='taiwan';
c('156013 russia ','russia ','россия','russian federation',
'russia / austria')='russia';
c('america','arizona','california','ap','美國','wa','washington','wisconsin',
'アメリカ合衆国','vereinigte staaten','usa / philippines','usa/germany','va',
'usa ','usa','us ','united states of america ','united states of america',
'texas','united states ','us','new mexico','oh.','nm',
'united stated','u.s.a.','u.s.a','u.s. ','u.s.','co','united states',
'u.s','nv','ny','north carolina ','new jersey','los angeles',
'florida usa','florida','rhode island','hawaii','ga')='usa';
c('p.r.c','中国')='china';
c('norwar')='norway';
c('phils','philippines ','pilipinas','ph')='philippines';
c('uk and belgium','uk ','england uk','united kingdom','united kingdon',
'united kingdom ','england','england ','england and qatar','kent',
'wales','england ','scotland, uk','scotland','northern ireland')='uk';
c('united arab emirates ','uae ','uae','ua')='united arab emirates';
c('kingdom of saudi arabia')='saudi arabia';
c('hong kong ')='hong kong';
c('france ')='france';
c('italia')='italy';
c('españa')='spain';
c('switzerland ')='switzerland';
c('shizuoka ','shizuoka')='japan';
c('thailand ')='thailand';
c('holland','the netherland','the netherlands','netherlands ',
'nederland ','nederland','the netherlands ','rotterdam')='netherlands';
c('belgië ','belguim')='belgium';
c('brasil')='brazil';
c('polska')='poland';
c('singapore ')='singapore';
c('south africa ')='south africa';
c('australia ')='australia';
c('turkiye')='turkey';
c('sverige')='sweden';
c('brunei darussalam')='brunei';
c('canada ','canada ','ontario')='canada';
c('украина','uraine')='ukraine';
c('德国','wendlingen','germany ','gernamy','gr',
'deutschalnd','deutschland','de')='germany';
c('viet nam','việt nam')='vietnam';
c('south korea')='korea';
c('mexico ','méxico','san luis potosí ')='mexico';
c('malaysia`','malaysia ','malsysia','selangor ')='malaysia';
c('das')='undefined country'")
user1<-user[which(!is.na(user$City) & user$Country=="undefined country"),]
user2<-setdiff(user, user1)
user1$Country<-user1$City
user1$Country<-recode(user1$Country,
"c('washington, dc','washington dc','waconia, mn','usa, nj','usa ',
'us- northeast','us','unitedstates','united states of america',
'united states','u.s.a.','u.s.a','texas','sumner, wa','st louis',
'so california','seattle, wa','seattle','san mateo, ca','qdf',
'san francisco, ca','san francisco','san diego','raleigh','arlington',
'pittsburgh, pa','pembroke','oklahoma city','oakland, ca','kirkland',
'new york, ny','new jersey','mclean, va','los angeles','las vegas',
'hood river','houston','fort worth tx','florida','denver','dallas',
'co','chicago','ca, usa','boston','austin','augusta ga','atlanta')='usa';
c('wales','united kingdom','london','kent','england, uk','england')='uk';
c('melbourne ')='australia';
c('beijing')='china';
c('germany ','deutschland')='germany';
c('italia')='italy';
c('dubai, uae')='united arab emirates';
c('okinawa')='japan';
c('españa ')='spain';
c('south korea')='korea';
c('taipei')='taiwan';
c('philppines')='philippines';
c('polen')='poland';
c('rio de janeiro','brasil')='brazil';
c('indonesia, singapore')='indonesia';
c('vancouver','toronto','canada ','calgary')='canada';
c('salzburg')='austria';
c('istanbul')='turkey';
c('the netherlands','nederland','amsterdam')='netherlands'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment