R从字符串中删除非字母数字符号 [英] R remove non-alphanumeric symbols from a string

查看:618
本文介绍了R从字符串中删除非字母数字符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,我想删除所有非字母数字符号,然后放入一个矢量。所以这个:

I have a string and I want to remove all non-alphanumeric symbols from and then put into a vector. So this:

"This is a string.  In addition, this is a string!" 

会变成:

would become:

>stringVector1

"This","is","a","string","In","addition","this","is","a","string"

我看过 grep()但找不到匹配的示例。任何建议?

I've looked at grep() but can't find an example that matches. Any suggestions?

推荐答案

这里是一个例子:

here is an example:

> str <- "This is a string. In addition, this is a string!"
> str
[1] "This is a string. In addition, this is a string!"
> strsplit(gsub("[^[:alnum:] ]", "", str), " +")[[1]]
 [1] "This"     "is"       "a"        "string"   "In"       "addition" "this"     "is"       "a"       
[10] "string"  

这篇关于R从字符串中删除非字母数字符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆