title: R: convert email addresses into unique integers
body: <p>R beginner with what seems to be a pretty simple problem :
  I have a number of email logs that I have read into R in the format:</p>
  
  <pre><code>&gt;log1
      Date        Time            From                 To
  1   2000-01-01  00:00:00    bob@mail.com            test1@mail.com
  2   2000-01-02  01:00:00    carolyn @mail.com       test2@mail.com
  3   2000-01-03  02:00:00    chris@mail.com          test3@mail.com
  4   2000-01-04  03:00:00    chris @mail.com         test4@mail.com
  5   2000-01-05  04:00:00    alan@mail.com           test5@mail.com
  6   2000-01-06  05:00:00    alan.@mail.com          test6@mail.com
  </code></pre>
  
  <p>I need to change log1$From and log1$To to a global unique numeric identifier, such that when I read in other logs later any given email address will receive the same identifier as previous logs. </p>
  
  <p>I have tried:</p>
  
  <pre><code>id &lt;- as.numeric(as.character(log1[,3])))
  id&lt;-as.numeric(levels(log1[,3])))
  id &lt;- charToRaw(log1[,4]), base=16)
  </code></pre>
  
  <p>Would some kind soul please help me out – Thanks!</p>
  
  <p>Apologies should probably have included this:</p>
  
  <pre><code> Date=c( "01/01/2000" ,"02/01/2000" ,"03/01/2000", "04/01/2000" ,"05/01/2000" ,"06/01/2000","07/01/2000","08/01/2000",
      "09/01/2000","10/01/2000","11/01/2000", "12/01/2000" ,"13/01/2000", "14/01/2000", "15/01/2000","16/01/2000"
      ,"17/01/2000","18/01/2000","19/01/2000","20/01/2000","01/01/2000","02/01/2000")
      Time=c("00:00:00","01:00:00","02:00:00", "03:00:00" ,"04:00:00" ,"05:00:00", "06:00:00" ,"07:00:00", "08:00:00", "09:00:00" ,"10:00:00",
      "11:00:00", "12:00:00","13:00:00", "14:00:00","15:00:00","16:00:00","17:00:00","18:00:00","19:00:00","00:00:00" ,"00:00:00")
      From=c("bob.shults@mail.com","carolyn.green@mail.com","chris.long@mail.com","christi.nicolay@mail.com","alan.aronowitz@mail.com","alan.comnes@mail.com",
      "dab@sprintmail.com","ana.correa@mail.com","andrew.fastow@mail.com","elena.kapralova@mail.com","bob.shults@mail.com","carolyn.green@mail.com",
      "chris.long@mail.com","christi.nicolay@mail.com","alan.aronowitz@mail.com","alan.comnes@mail.com","dab@sprintmail.com","ana.correa@mail.com",
      "andrew.fastow@mail.com","elena.kapralova@mail.com","bob.shults@mail.com","bob.shults@mail.com")
      To=c("ana.correa@mail.com","test2@mail.com","test3@mail.com","test4@mail.com","test5@mail.com","test6@mail.com","test7@mail.com",
      "test8@mail.com","test9@mail.com","test10@mail.com","test11@mail.com","test12@mail.com","test13@mail.com","test14@mail.com",
      "test15@mail.com","test16@mail.com","test17@mail.com","test18@mail.com","test19@mail.com","test20@mail.com","ana.correa@mail.com","ana.correa@mail.com")
      log&lt;-data.frame(Date=Date,Time=Time,From=From,To=To)
  </code></pre>
  
  <p>Attempt at using MD5 to generate globally unique identifiers: Note how the identifier for ana.correa@mail.com is a correct match within ID_to but is not within ID_from</p>
  
  <pre><code>ID_to&lt;-data.frame()
      ID_from&lt;-data.frame()
  
      for (i in 1:nrow(log)){
      to&lt;-as.numeric(paste('0x', substr(rep(hmac('secret',log[i,4], algo='md5'), 2), c(1, 9, 17, 25), c(8, 16, 24, 32)),sep=""))
      (ID_to&lt;-rbind(ID_to,to))
  
      from&lt;-as.numeric(paste('0x', substr(rep(hmac('secret',log[i,3], algo='md5'), 2), c(1, 9, 17, 25),c(8, 16, 24, 32)),sep=""))
      (ID_from&lt;-rbind(ID_from,from))
  
      }
  
      ID_to[,3]&lt;-paste(ID_to[,1],ID_to[,2], sep="")
      ID_from[,3]&lt;-paste(ID_from[,1],ID_from[,2], sep="")
  
      edgelist&lt;-data.frame(ID_from[,3],log[,3],ID_to[,3],log[,4],log[,1],log[,2])
      print(edgelist)
      ID_from...3.                 log...3.           ID_to...3.            log...4.   log...1. log...2.
      27488842661591306920      bob.shults@mail.com 18727221862165338513 ana.correa@mail.com 01/01/2000 00:00:00
      38124472891255273775   carolyn.green@mail.com  1251903296725454474      test2@mail.com 02/01/2000 01:00:00
      29070047663451376630      chris.long@mail.com 17074276751156451031      test3@mail.com 03/01/2000 02:00:00
      8261398433828474582 christi.nicolay@mail.com  1563683670909194033      test4@mail.com 04/01/2000 03:00:00
      18727221862165338513  alan.aronowitz@mail.com 26735368323826533112      test5@mail.com 05/01/2000 04:00:00
      5680838251168988404     alan.comnes@mail.com  2923605896229594830      test6@mail.com 06/01/2000 05:00:00
      2351312285811012730       dab@sprintmail.com 17171333544033270402      test7@mail.com 07/01/2000 06:00:00
      328278708432069254      ana.correa@mail.com 33840664403556851587      test8@mail.com 08/01/2000 07:00:00
      1127901879852039037   andrew.fastow@mail.com  1973548136161209824      test9@mail.com 09/01/2000 08:00:00
      7349515121496417787 elena.kapralova@mail.com  5680838251168988404     test10@mail.com 10/01/2000 09:00:00
      27488842661591306920      bob.shults@mail.com   328278708432069254     test11@mail.com 11/01/2000 10:00:00
      38124472891255273775   carolyn.green@mail.com  1127901879852039037     test12@mail.com 12/01/2000 11:00:00
      29070047663451376630      chris.long@mail.com 27488842661591306920     test13@mail.com 13/01/2000 12:00:00
      8261398433828474582 christi.nicolay@mail.com 38124472891255273775     test14@mail.com 14/01/2000 13:00:00
      18727221862165338513  alan.aronowitz@mail.com 29070047663451376630     test15@mail.com 15/01/2000 14:00:00
      5680838251168988404     alan.comnes@mail.com  8261398433828474582     test16@mail.com 16/01/2000 15:00:00
      2351312285811012730       dab@sprintmail.com  2351312285811012730     test17@mail.com 17/01/2000 16:00:00
      328278708432069254      ana.correa@mail.com  7349515121496417787     test18@mail.com 18/01/2000 17:00:00
      1127901879852039037   andrew.fastow@mail.com 41762759923562968495     test19@mail.com 19/01/2000 18:00:00
      7349515121496417787 elena.kapralova@mail.com 24894056753582090007     test20@mail.com 20/01/2000 19:00:00
      27488842661591306920      bob.shults@mail.com 18727221862165338513 ana.correa@mail.com 01/01/2000 00:00:00
      27488842661591306920      bob.shults@mail.com 18727221862165338513 ana.correa@mail.com 02/01/2000 00:00:00
  </code></pre>
  
  <p>Attempt at levels/factor method: </p>
  
  <p>Getting an error:</p>
  
  <pre><code>log &lt;- union(levels(log[,3]), levels(log[,4]))
  &gt;Error in emails[, 3] : incorrect number of dimensions
  </code></pre>