Skip to content

Instantly share code, notes, and snippets.

@sfirke
Created July 5, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfirke/a7aeca98a271d52c740563a821dce4b4 to your computer and use it in GitHub Desktop.
Save sfirke/a7aeca98a271d52c740563a821dce4b4 to your computer and use it in GitHub Desktop.
separating first and last names in email
library(stringr)
get_part_before_dot <- function(email){
x <- str_split(email, "[.]")
lapply(x, `[[`, 1) %>%
unlist
}
dat <- data.frame(email = c("robert.rosen@tntp.org", "Sam.firke@tntp.org"))
dat <- dat %>%
separate(email, into = c("email", "domain"), sep = "@") %>%
separate( ... ON THE DOT)
dat %>%
rowwise() %>%
mutate(first = get_first_last_dot(email)[1],
last = get_first_last_dot(email)[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment