Using strsplit and sapply with email

Post date: Jun 11, 2014 4:14:02 PM

We can use strsplit to separate email address thatsme@mydomain.com into local-part (thatsme) and domain (mydomain.com). Below is the example

email <- c("bot@gmaw.com","me@shi-thead.com","noway@ohyes.net") splitname <- strsplit(x=email, split='@') local.part <- sapply(splitname, "[", 1) domain.part <- sapply(splitname, "[", 2)

The result would be

> local.part [1] "bot"   "me"    "noway" > domain.part [1] "gmaw.com"      "shi-thead.com" "ohyes.net" 

Note that we can use "[" to select component from list in R.

tags: strsplit, list, decompose, split, email