如何删除R中除特殊标点符号外的所有英文单词
how to delete all English words, except special punctuation, in R
我在 R 中有一个数据文件,
data <- "conflict need resolved :< turned conversation exchange ideas richer environment one tricky concepts :D conflict always top business agendas :> maybe different ideas opinions different :)"
从这里我想删除所有单词,只有微笑会在那里,以及我期待的输出,
":< :D :> :)"
R 中是否有任何库或方法可以轻松完成此任务?
您可以使用 [[:alnum:]]
作为字符串中所有数字和字母数字字符的正则表达式模式
s <- gsub("[[:alnum:]]*", "", "conflict need resolved :< turned conversation exchange ideas richer environment one tricky concepts :D conflict always top business agendas :> maybe different ideas opinions different :) ")
gsub(" +", " ", s)
[1] " :< : :> :) "
我在 R 中有一个数据文件,
data <- "conflict need resolved :< turned conversation exchange ideas richer environment one tricky concepts :D conflict always top business agendas :> maybe different ideas opinions different :)"
从这里我想删除所有单词,只有微笑会在那里,以及我期待的输出,
":< :D :> :)"
R 中是否有任何库或方法可以轻松完成此任务?
您可以使用 [[:alnum:]]
作为字符串中所有数字和字母数字字符的正则表达式模式
s <- gsub("[[:alnum:]]*", "", "conflict need resolved :< turned conversation exchange ideas richer environment one tricky concepts :D conflict always top business agendas :> maybe different ideas opinions different :) ")
gsub(" +", " ", s)
[1] " :< : :> :) "