提取某个子字符串(电子邮件地址) [英] Extracting a certain substring (email address)
问题描述
我试图从一个看起来像这样的变量中提取一些:
I'm attempting to pull some a certain from a variable that looks like this:
v1 <- c("Persons Name <personsemail@email.com>","person 2 <person2@email.com>")
(这个变量有数百个观察值)
(this variable has hundreds of observations)
我想最终创建第二个变量来提取他们的电子邮件以提供此输出:
I want to eventually make a second variable that pulls their email to give this output:
v2 <- c("personsemail@email.com", "person2@email.com")
我该怎么做?有我可以使用的特定软件包吗?或者我是否需要创建一个包含 grep
和 substr
的函数?
How would I do this? Is there a certain package I can use? Or do I need to make a function incorporating grep
and substr
?
推荐答案
那些看起来就像 R 可能称之为人"的东西.有一个 as.person()
函数可以拆分电子邮件地址.例如
Those look like what R might call a "person". There is an as.person()
function that can split out the email address. For example
v1 <- c("Persons Name <personsemail@email.com>","person 2 <person2@email.com>")
unlist(as.person(v1)$email)
# [1] "personsemail@email.com" "person2@email.com"
有关详细信息,请参阅 ?person
帮助页面.
For more information, see the ?person
help page.
这篇关于提取某个子字符串(电子邮件地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!