[R] R help
arun
smartpink111 at yahoo.com
Thu Feb 6 18:05:51 CET 2014
Hi,
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))
res <- setNames(cbind(dat,do.call(rbind,lapply(seq_along(vec1),function(i) if(i %in% indx1){strsplit(vec1[i],"[_ at .]")[[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 Thursday, February 6, 2014 4:16 AM, Malyadri Putchakayala <malyadri.putchakayala at nuevora.com> wrote:
Hi,
Emails
Mal123 at gmail.com
Mahi.r at gmail.com
Ravi_123 at yahoo.com
Lavk.lll at rediff.com
xyz at gmail.com
xy at 12_g.com
I need split firstname,lastname,domail(only gmail,not gmail.com),also 123 in
last name,so please give me help
Output is
Emails f.name l.name domain
Mal123 at gmail.com mal 123 gmail
Mahi.r at gmail.com mahi r gmail
Ravi_123 at yahoo.com ravi 123 gmail
Lavk.lll at rediff.com lavk 111 gmail
xyz at gmail.com xyz gmail
xy at 12_g.com xy 12_g
Please give me solution
More information about the R-help
mailing list