为什么我在 1:nrow(counts) 中收到错误:长度为 0 的参数

Why am I getting an error in 1:nrow(counts) : argument of length 0

我正在使用 R 中的 topicmodels 包进行主题建模。我正在创建一个 Corpus 对象,进行一些基本的预处理,然后创建一个 DocumentTermMatrix:

library(topicmodels)

#Set parameters for Gibbs sampling
burnin <- 4000
iter <- 2000
thin <- 500
seed <-list(2003,5,63,100001,765)
nstart <- 5
best <- TRUE

#Number of topics
k <- 8

#Run LDA using Gibbs sampling
# Start the clock!
ptm <- proc.time()
ldaOut <-LDA(dtm.new,k, method="Gibbs", control=list(nstart=nstart, seed = seed, best=best, 
                                                  burnin = burnin, iter = iter, thin=thin))
# Stop the clock
proc.time() - ptm

然后我在最后一行得到了错误

 #docs to topics

ldaOut.topics <- as.matrix(topics(ldaOut))

这是错误:

error in 1:nrow(counts) : argument of length 0

我假设这意味着它不能计算第一行。有没有办法检查。

topics() 不是已经给你一个矩阵了吗?

无论如何,"argument of length zero" 告诉您对象 "counts" 有零行。