[R] R help
arun
smartpink111 at yahoo.com
Fri Feb 7 17:38:09 CET 2014
Hi,
The pattern is not very clear.
Try:
dat <- read.table(text="Emails
Mal123 at gmail.com
Mahi.r at gmail.com
xyz at gmail.com
Ravi_123 at yahoo.com
Lavk.lll at rediff.com
xy at 12_g.com",sep="",header=TRUE,stringsAsFactors=FALSE)
vec1 <- gsub("\\.[[:alnum:]]+$","",gsub("^([[:alpha:]]+)(\\d+.*)","\\1_\\2",dat$Emails))
indx1 <- grep("[[:punct:]]+",gsub("\\@.*","",vec1))
indx2 <- grep("@.*_",vec1)
res <- setNames(cbind(dat,do.call(rbind,lapply(seq_along(vec1),function(i) if(i %in% indx1){strsplit(vec1[i],"[_ at .]")[[1]]} else if(i %in% indx2) c(strsplit(vec1[i],"@")[[1]],"") else strsplit(gsub("(.*)(\\@.*)","\\1*\\2",vec1[i]),"[*@]")[[1]]))),c("Emails","f.name","l.name","domain"))
res[sapply(res,is.factor)] <- lapply(res[sapply(res,is.factor)],as.character)
res
# Emails f.name l.name domain
#1 Mal123 at gmail.com Mal 123 gmail
#2 Mahi.r at gmail.com Mahi r gmail
#3 xyz at gmail.com xyz gmail
#4 Ravi_123 at yahoo.com Ravi 123 yahoo
#5 Lavk.lll at rediff.com Lavk lll rediff
#6 xy at 12_g.com xy 12_g
A.K.
On Friday, February 7, 2014 1:41 AM, Malyadri Putchakayala <malyadri.putchakayala at nuevora.com> wrote:
HI,
Emails f.name l.name domain
#1 Mal123 at gmail.com Mal 123 gmail
#2 Mahi.r at gmail.com Mahi r gmail
#3 xyz at gmail.com xyz gmail
#4 Ravi_123 at yahoo.com Ravi 123 yahoo
#5 Lavk.lll at rediff.com Lavk lll rediff
#6 xy at 12_g.com xy 12_g
ABOVE IS ALL ARE RIGHT.BUT MY REQUIREMENT IS 12_G IS ALSO LAST NAME
Emails f.name l.name domain
#1 Mal123 at gmail.com Mal 123 gmail
#2 Mahi.r at gmail.com Mahi r gmail
#3 xyz at gmail.com xyz gmail
#4 Ravi_123 at yahoo.com Ravi 123 yahoo
#5 Lavk.lll at rediff.com Lavk lll rediff
#6 xy at 12_g.com xy 12_g
MY FINAL OUTPUT IS THIS TYPE.IF POSSIBLE PLEASE HELP ME.
More information about the R-help
mailing list