2013-03-02 292 views
24

我在R中有一個字符串,其中包含大量的單詞。當觀看字符串,我收到了大量的文本,其中包括類似下面的文字:從R中的字符串中刪除某些字符

>docs 

.... 

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

.... 

所以我不知道如何刪除這些\ u009字符(所有的人,其中有一些稍微不同的號碼)從字符串。我試過使用gsub(),但是這並不有效地從字符串中刪除內容。

回答

40

這應該工作

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

4

嘗試: gsub('\\$', '', '$5.00$')