mardi 16 juillet 2019

How to transform an email address name? Ex, 'ab_1@email.com' to 'VCSN@email.com' (vowel-consonant-symbol-number))

I'm trying to analyze email addresses name (anything before the @ symbol)in r for pattern detection. I want transform each element to a representation. For example, 'ty_00@mail.com' would be 'CCSNN' (consonant-consonant-symbol-number-number). I'm trying to use an ifelse() statement but it isn't working. Maybe a function would work better? But my coding skills are somewhat limited.

n =c('1','2','3','4','5','6','7','8','9','0')
v=c('a','e','i','o','u')
c=c('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z')
s=c("!","#","$","%","&","'","*","+","-","/","=","?","^","_","`","{")



string1= 'jack0_d'
data$string1 <- ifelse(data$string1 %in% n, "N","?" |
                       data$string1 %in% v, "V","?" |
                       data$string1 %in% c, "C","?" |
                       data$string1 %in% s, "S","?" )

'Error in ifelse(data$string1 %in% n, "N", "?" | data$string1 %in% v, "V",  : 
  unused arguments ("V", "?" | data$string1 %in% c, "C", "?" | data$string1 %in% s, "S", "?")'

'jack0_d' would be CVCCNSC

Aucun commentaire:

Enregistrer un commentaire