【发布时间】:2014-06-09 15:01:58
【问题描述】:
我正在使用 R 处理 Twitter 数据集,我发现很难从推文中删除用户名。
这是我的数据集的推文列中的推文示例:
[1] "@danimottale: 2 bad our inalienable rights offend their sensitivities. U cannot reason with obtuse zealotry. // So very well said."
[2] "@FreeMktMonkey @drleegross Want to build HSA throughout lifetime for when older thus need HDHP not to deplete it if ill before 65y/o.thanks"
我想删除/替换所有以“@”开头的单词以获得此输出:
[1] "2 bad our inalienable rights offend their sensitivities. U cannot reason with obtuse zealotry. // So very well said."
[2] "Want to build HSA throughout lifetime for when older thus need HDHP not to deplete it if ill before 65y/o.thanks"
这个 gsub 函数仅用于删除“@”符号。
gsub("@", "", tweetdata$tweets)
我想说的是,删除文本符号后面的字符,直到遇到空格或标点符号。
我开始尝试只处理空间但无济于事:
gsub("@.*[:space:]$", "", tweetdata$tweets)
这会完全删除第二条推文
gsub("@.*[:blank:]$", "", tweetdata$tweets)
这不会改变输出。
我会很感激你的帮助。
【问题讨论】: