我想从多个字符向量中删除多个模式。目前我要去:
a.vector <- gsub("@\\w+", "", a.vector)
a.vector <- gsub("http\\w+", "", a.vector)
a.vector <- gsub("[[:punct:]], "", a.vector)
等等等等
这很痛苦。我在看这个问题和答案:R:gsub,模式=向量和替换=向量,但这并没有解决问题。
themapply
和 themgsub
都不起作用。我制作了这些矢量
remove <- c("@\\w+", "http\\w+", "[[:punct:]]")
substitute <- c("")
既不mapply(gsub, remove, substitute, a.vector)
也不mgsub(remove, substitute, a.vector) worked.
a.vector
看起来像这样:
[4951] "@karakamen: Suicide amongst successful men is becoming rampant. Kudos for staing the conversation. #mental"
[4952] "@stiphan: you are phenomenal.. #mental #Writing. httptxjwufmfg"
我想:
[4951] "Suicide amongst successful men is becoming rampant Kudos for staing the conversation #mental"
[4952] "you are phenomenal #mental #Writing" `