Skip to content

topfeatures(x, group = something) fails with weighted dfms #2032

@kbenoit

Description

@kbenoit

Discovered in https://stackoverflow.com/questions/59148580/whats-the-correct-way-to-extract-tf-idf-topfeatures-by-document/59152416?noredirect=1#comment115615693_59152416:

library("quanteda")
## Package version: 2.1.2

dfmat <- dfm(c("a b b b c c d", "a a b d d"))

topfeatures(dfmat, n = 1, groups = c("group1", "group2"))
## $group1
## b 
## 3 
## 
## $group2
## a 
## 2

topfeatures(dfm_tfidf(dfmat), n = 1, groups = c("group1", "group2"))
## Error: will not group a weighted dfm; use force = TRUE to override

Solution is to use force = TRUE by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions