我想從多個字符向量中刪除多個模式。目前,我打算:從文本向量中刪除多個模式r
a.vector <- gsub("@\\w+", "", a.vector)
a.vector <- gsub("http\\w+", "", a.vector)
a.vector <- gsub("[[:punct:]], "", a.vector)
等等等等
這是痛苦的。我正在看這個問題&回答:R: gsub, pattern = vector and replacement = vector但它沒有解決問題。
無論是mapply
還是mgsub
的工作。我做了這些載體
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" `