[英]how to delete all English words, except special punctuation, in R
I have a data file 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 :)"
from this I want to remove all words, only the smiles will be there, and the output I am expecting, 我想从中删除所有单词,只有微笑会在那里,以及我期望的输出,
":< :D :> :)"
Is there any library or method in R for doing this task easily? R中是否有任何库或方法可以轻松完成此任务?
You can use [[:alnum:]]
as a regexp pattern for all numeric and alphanumeric characters of a string 您可以将
[[: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] " :< : :> :) "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.