我正在研究 R 的 tm 包中的定性分析项目。我已经建立了一个语料库并创建了一个术语文档矩阵,长话短说我需要编辑我的术语文档矩阵并合并它的一些行。为此,我已将其从 R 中导出,使用
write.csv()
然后我将 csv 文件导入回 R,但我正在努力弄清楚如何让 R 将其读取为 aTermDocumentMatrix
或DocumentTermMatrix
.
我尝试使用以下示例代码的建议但无济于事。
它似乎一直在阅读我的矩阵,就好像它是一个语料库,每个单元格都是一个文档。
# change this file location to suit your machine
file_loc <- "C:\\Documents and Settings\\Administrator\\Desktop\\Book1.csv"
# change TRUE to FALSE if you have no column headings in the CSV
x <- read.csv(file_loc, header = TRUE)
require(tm)
corp <- Corpus(DataframeSource(x))
dtm <- DocumentTermMatrix(corp)
是否有任何方法可以导入 csv 矩阵,该矩阵将被读取为termdocumentmatrix
或documenttermmatrix
不让 R 读取 csv,就好像每个单元格都是文档一样?