I want to split a column containing emailaddresses at the “@”.
d$domain<-strsplit( d$email, "@")[[1]]
Does not work. What is the correct way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(Maybe) more than one line is necessary:
(Note:
d$emailmust becharacterand notfactorand while you used 1 as the index in your question, the index of 2 will correspond to an email’s domain)Update: I think there is still a way to complete this task in one line by using ‘apply’ but I’m not sure how to do this … yet.
One line answer (after defining function):
fn <- function(x){unlist(strsplit(x,"@"))[2]}d$domain <- lapply(d$email, fn)