0
我嘗試創建文檔項矩陣時出現以下代碼,但出現錯誤:(最初我的數據是在一列csv文件中,並且讀取了的.csv,但複製的目的,我創建了下面一個數據幀)嘗試在R中創建文檔項矩陣時出錯
library(tm)
TEXTS<- as.data.frame(c("I am a cat person", "I like both cats and dogs"), stringsAsFactors = FALSE)
docs<-VCorpus(VectorSource(TEXTS))
docs <- tm_map(docs, removePunctuation)
docs <- tm_map(docs, removeNumbers)
docs <- tm_map(docs, content_transformer(tolower), lazy = TRUE)
docs <- tm_map(docs, PlainTextDocument, lazy = TRUE)
docs <- tm_map(docs, removeWords, stopwords("english"), lazy = TRUE)
library(SnowballC)
docs <- tm_map(docs, stemDocument, language = meta(docs, "english"), lazy = TRUE)
dtm <- DocumentTermMatrix(docs)
這是我從最後一行出現錯誤:
Error in stemDocument.PlainTextDocument(x, ...) :
promise already under evaluation: recursive default argument reference or earlier problems?
In addition: Warning message:
In stemDocument.PlainTextDocument(x, ...) :
restarting interrupted promise evaluation
我能做些什麼? 謝謝
謝謝。如果我有我的數據框在一個csv文件,而不是我如何顯示它上面,我可以這樣做:texts <-as.data.frame(read.csv(「descriptions.csv」,header = TRUE,stringsAsFactors = FALSE))文檔<-VCorpus(VectorSource(文本))。當我使用與上面相同的代碼時,dtm <-DocumentTermMatrix(docs)時出現此錯誤:gsub中的錯誤(sprintf(「(* UCP)\\ b(%s)\\ b」),粘貼(排序(字,遞減= TRUE),: 輸入字符串715無效UTF-8 –
當您正在讀取csv文件時,您將其轉換爲數據幀,我想這個數據幀有多個列。這個變量包含了'VCorpus'函數的文本,也許這個錯誤是由於輸入錯誤而觸發的。如果你可以提供一個csv的提取文件,我也可以試試。 –
我的數據幀只有一列 - 但是我嘗試使用文本$ Long_Description並且它仍然不起作用我不確定我怎樣才能讓你看到csv文件,但是它有一列專用權限「Long_Description」,它們是前幾行(逗號表示新行):我是貓人, 我喜歡貓狗, 我討厭寵物, 我沒有任何寵物, 我只喜歡小動物, 我是一個狗人;但我也有一隻寵物兔子 –