У меня есть следующий код:Документ Термин матрица R
rm(list=ls(all=TRUE)) #clear data
setwd("~/UCSB/14 Win 15/Issy/text.fwt") #set working directory
files <- list.files(); head(files) #load & check working directory
fw1 <- scan(what="c", sep="\n",file="fw_chp01.fwt")
library(tm)
corpus2<-Corpus(VectorSource(c(fw1)))
skipWords<-(function(x) removeWords(x, stopwords("english")))
#remove punc, numbers, stopwords, etc
funcs<-list(content_transformer(tolower), removePunctuation, removeNumbers, stripWhitespace, skipWords)
corpus2.proc<-tm_map(corpus2, FUN = tm_reduce, tmFuns = funcs)
corpus2a.dtm <- DocumentTermMatrix(corpus2.proc, control = list(wordLengths = c(1,110))) #create document term matrix
Я пытаюсь использовать некоторые из операций подробно в справочном руководстве по тм (http://cran.r-project.org/web/packages/tm/tm.pdf) с небольшим успехом. Например, когда я пытаюсь использовать findFreqTerms, я получаю следующее сообщение об ошибке:
Error: inherits(x, c("DocumentTermMatrix", "TermDocumentMatrix")) is not TRUE
Can
никому ключ мне в том, почему это не работает, и что я могу сделать, чтобы исправить это?
отредактированные для @lawyeR:
головки (fw1) производят первые шесть строк текста (Эпизод 1 из Finnegans Wake Джеймс Джойс):
[1] "003.01 riverrun, past Eve and Adam's, from swerve of shore to bend"
[2] "003.02 of bay, brings us by a commodius vicus of recirculation back to"
[3] "003.03 Howth Castle and Environs."
[4] "003.04 Sir Tristram, violer d'amores, fr'over the short sea, had passen-"
[5] "003.05 core rearrived from North Armorica on this side the scraggy"
[6] "003.06 isthmus of Europe Minor to wielderfight his penisolate war: nor"
осматривает (corpus2) выводит каждую строку текст в следующем формате (это последняя строка текста):
[[960]]
<<PlainTextDocument (metadata: 7)>>
029.36 borough. #this part differs by line of course
инспектировать (corpus2a.dtm) возвращает таблицу всех типов (есть 4163 в общей сложности (в тексте в т он следующий формат:
Docs youths yoxen yu yurap yutah zee zephiroth zine zingzang zmorde zoom
1 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0
Можете ли вы включить в свой вопрос, что возвращается с головы (fw1)? Кроме того, включите то, что возвращается из инспекции (corpus2). Наконец, для диагностики выясняется, что производит проверка (corpus2a.dtm)? – lawyeR
@lawyeR Я включил эти результаты в редактирование вопроса. Спасибо за вашу помощь! – hooliaquoolia