2017-07-03 101 views
0

我正在使用tm包清理Twitter語料庫。但是,該軟件包無法清理表情符號。使用tm包刪除R中的圖釋

這裏有一個重複的代碼:

July4th_clean <- tm_map(July4th_clean, content_transformer(tolower)) 
Error in FUN(content(x), ...) : invalid input 'RT ElleJohnson Love of country is encircling the globes ������������������ july4thweekend July4th FourthOfJuly IndependenceDay NotAvailableOnIn' in 'utf8towcs' 

有人點我在正確的方向,除去使用TM封裝的表情?

謝謝

路易斯

+0

從你的例子中不清楚你想要消除什麼。您是否想要消除包含多個連續標點符號的子字符串,如:-)和(-_-),還是想要消除奇怪的Unicode字符(如☺和❀)? – G5W

+0

你說得對。我認爲這是一個或類似的東西。 – Luis

+0

我是R新手。你知道我可以如何檢查特定的推文嗎?我想象你使用[]但不知道如果功能或代碼的任何其他部分。 – Luis

回答

0

你可以試試這個功能

iconv(July4th_clean, "latin1", "ASCII", sub="") 

重複的問題,see post

+0

嗨澤亞德,我確實看到一個,但猶豫使用它,因爲代碼是不同於我正在使用的tm代碼。我正在使用< - tm_map函數。 – Luis

+0

你應該在使用'tm'包之前運行它 –

0

您可以使用gsub擺脫所有非ASCII字符。

Texts = c("Let the stormy clouds chase, everyone from the place ☁ ♪ ♬", 
    "See you soon brother ☮ ", 
    "A boring old-fashioned message") 

gsub("[^\x01-\x7F]", "", Texts) 
[1] "Let the stormy clouds chase, everyone from the place " 
[2] "See you soon brother "         
[3] "A boring old-fashioned message" 

詳情: 您可以[ ]在正則表達式的指定字符類別。當類描述以^開頭時,它表示除這些字符以外的所有內容。在這裏,我已經指定了除字符1-127之外的所有內容,即除標準ASCII之外的所有內容,並且我已指定它們應該替換爲空字符串。