Q:

Extract Email and Put it in Adjacent Row

I have dataset.
v1 <- c("I will try to fix you usman@usman.com", "I will try to fix you", "Zombies Zombies xyz@ymail.com")
v2 < c("ABC", "XYZ", "Oh Game")
dx <- data.frame(v1, v2)

I extract the emails from v1 using 
regmatches(dx$v1, regexpr("[[:alnum:]]+\\@[[:alpha:]]+\\.com", dx$v1))
This works.
I just want to put the email adjacent to the v2 in dx
such that.
ABC       usman@usman.com
XYZ       NA
Oh Game   xyz@ymail.com

Seems pretty basic but I am unable to figure out.

A:

One way could be
dx$emails <- sapply(dx$v1, function(x) {
  email <- regmatches(x, regexpr("[[:alnum:]]+@[[:alpha:]]+\\.com", x))
  (result <- ifelse(identical(email, character(0)), NA, email))
})

This basically checks if at least one match was found.

If you don't mind installing a package, use stringr and put parentheses around your expression (the @ does not need to be escaped):
library(stringr)
dx$emails <- str_extract(dx$v1, "([[:alnum:]]+@[[:alpha:]]+\\.com)")

Both will yield
                                     v1      v2          emails
1 I will try to fix you usman@usman.com     ABC usman@usman.com
2                 I will try to fix you     XYZ            <NA>
3         Zombies Zombies xyz@ymail.com Oh Game   xyz@ymail.com

