Sometimes when you are coding something you need to make a test This is a test It is only a test of the gsub function
#install.packages("stringr")
library(stringr)
email <- c('phillip.allen@yahoo.com', 'bruce.wayne@gmail.com', 'clark.kent@gmail.com', 'mary.smith@yahoo.com')
test_emails <- data.frame(email)
print(test_emails)
## email
## 1 phillip.allen@yahoo.com
## 2 bruce.wayne@gmail.com
## 3 clark.kent@gmail.com
## 4 mary.smith@yahoo.com
test_emails$names <- str_extract(test_emails$email, "^[^@]*(?=@)")
head(test_emails)
## email names
## 1 phillip.allen@yahoo.com phillip.allen
## 2 bruce.wayne@gmail.com bruce.wayne
## 3 clark.kent@gmail.com clark.kent
## 4 mary.smith@yahoo.com mary.smith
test_emails <- gsub("[[:punct:]]", " ", test_emails$names)
test <-data.frame(test_emails)
head(test)
## test_emails
## 1 phillip allen
## 2 bruce wayne
## 3 clark kent
## 4 mary smith