从R中的字符串中删除某些字符

问题描述:

我在R中有一个字符串,其中包含大量的单词。当观看字符串,我收到了大量的文本,其中包括类似下面的文字:从R中的字符串中删除某些字符

>docs 

.... 

\u009cYes yes for ever for ever the boys cried in their ringing voices with softened faces 

.... 

所以我不知道如何删除这些\ u009字符(所有的人,其中有一些稍微不同的号码)从字符串。我试过使用gsub(),但是这并不有效地从字符串中删除内容。

这应该工作

gsub('\u009c','','\u009cYes yes for ever for ever the boys ') 
"Yes yes for ever for ever the boys " 

这里009C是unicode的十六进制数。您必须始终指定4个十六进制数字。 如果你有很多,一种解决方案是通过管道将它们分开:

gsub('\u009c|\u00F0','','\u009cYes yes \u00F0for ever for ever the boys and the girls') 

"Yes yes for ever for ever the boys and the girls" 
+0

谢谢,这得到了它的工作。 – 2013-03-02 04:19:54

+1

关于“您必须始终指定4位数字”: 这只是在执行unicode时。这应该删除空格和破折号: 'gsub('| - ','','1-444-654')' – Zak 2015-08-30 18:45:55

尝试: gsub('\\$', '', '$5.00$')