Skip to content

convert(x, to = "stm") needs warning when dfm contains zero-count features #700

Description

@kbenoit
mydfm <- as.dfm(matrix(c(1, 0, 2, 0, 
                         0, 0, 1, 2, 
                         1, 0, 0, 0, 
                         1, 0, 3, 4), byrow = TRUE, nrow = 4))
mydfm
# Document-feature matrix of: 4 documents, 4 features (50% sparse).
# 4 x 4 sparse Matrix of class "dfmSparse"
#         features
#   docs   feat1 feat2 feat3 feat4
#   doc1     1     0     2     0
#   doc2     0     0     1     2
#   doc3     1     0     0     0
#   doc4     1     0     3     4

stm(mydfm, K = 2)
# Error in stm.list(documents = stmdfm$documents, vocab = stmdfm$vocab,  : 
#   Word indices must be sequential integers starting with 1.
                  
stmdfm <- convert(mydfm, to = "stm")
stm(documents = stmdfm$documents, vocab = stmdfm$vocab, K = 2)
# Error in stm.list(documents = stmdfm$documents, vocab = stmdfm$vocab,  : 
#   Word indices must be sequential integers starting with 1.

I will also file an issue on the stm GitHub page.

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions