2016-12-25 8 views
1

データフレーム内の「宛先」列から特定の電子メール(@ enron.com)を抽出したい。一部の行に複数の電子メールがある。例えば、私はこれを持っています:[email protected], [email protected], [email protected], [email protected], [email protected],[email protected], [email protected]。私の質問は、この列からEnronドメイン(@ enron.com)の電子メールだけを抽出して新しい列に保存する方法ですが、抽出することはできますが、問題があると、行には20行の電子メールのうち10行のエンロン電子メールが含まれています。エンロン電子メールを10行ではなく1行にまとめたいのですが、How to extract expression matching an email address in a text file using R or Command Line?,emails = regmatches(df, gregexpr("([_a-z0-9-]+(\\.[_a-z0-9-]+)*@enron.com)", df))のコードを実行しますが、このエラーはError in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 2, 0, 5です。列内の異なる電子メールから特定の電子メールを抽出する - R

+0

あなたは、入力データのサンプルと所望の出力を共有することはできますでしょうか? – Psidom

答えて

1

単一の行に複数のメールがある場合私たちは、この

subset(df, grepl("enron.com", To)) 

ためgrepを使用することができ、str_extract

library(stringr) 
data.frame(To =sapply(str_extract_all(df$To, "\\[email protected]"), paste, collapse=",")) 
+1

ありがとうございました。 –

関連する問題