-1
我想在R中的語料庫中進行預處理,並且我需要刪除以$開頭的單詞。下面的代碼刪除$但不是$字,我很困惑。如何刪除以R開頭的語料庫中的單詞?
inspect(data.corpus1[1:2])
# <<SimpleCorpus>>
# Metadata: corpus specific: 1, document level (indexed): 0
# Content: documents: 2
#
# [1] $rprx loading mid .60's, think potential. 12m vol fri already 11m today
# [2] members report success see track record $itek $rprx $nete $cnet $zn $cwbr $inpx
removePunctWords <- function(x) {
gsub(pattern = "\\$", "", x)
}
data.corpus1 <-
tm_map(data.corpus1,
content_transformer(removePunctWords))
inspect(data.corpus1[1:2])
# <<SimpleCorpus>>
# Metadata: corpus specific: 1, document level (indexed): 0
# Content: documents: 2
#
# [1] rprx loading mid .60's, think potential. 12m vol fri already 11m today
# [2] members report success see track record itek rprx nete cnet zn cwbr inpx
我不是最好的正則表達式,但也許是「。」?例如:'gsub(pattern =「\\ $。*」,「」,x)'? – shea
@shea在第一個$之後會殺死所有的東西。您只需要消除$和立即出現的單詞字符。 – G5W
@ G5W感謝您解釋。我不知道這個「*」會是那麼貪婪。 – shea