Skip to content

Consider separating the grouping functions for corpus_ and dfm_ #725

Description

@kbenoit

Following on the discussion in #723 and #720, we should consider adding separate functions to perform the grouping of counts or texts currently present as arguments to the corpus() and dfm() constructor functions.

These would take grouping variables, and perform an aggregation function on the main object and on other variables.

  • corpus_group() - would aggregate the texts by pasting (similar to texts(x, groups = ) now), but take other arguments to allow docvars to be aggregated in a user-specified way, if these differ across the same values of the grouping variables.

  • dfm_group() - this would simply separate groups = functionality from the dfm(), and allow the user to aggregate dfm cell values (usually, counts, but could be weighted counts) by a grouping variable for documents. This is very easy with existing functions: we simply replace the docname row attribute by the unique grouping value label, and call dfm_compress(x, margin = "documents"). The default aggregation function would be sum but we could offer alternatives through a user-defined numerical function. We could add arguments to aggregate docvars too but this might be overly complicated - if the user wants this, he/she should do it at the corpus stage.

Rather than reinvent the wheel, we might consider using reshape2 syntax and putting this into corpus_reshape(). This would clarify #619 for instance (what are the differences between corpus_reshape() and corpus_segment()), since reshaping would offer functionality for moving up to aggregate units, rather than splitting/segmenting. An alternative would be to use dplyr functions such as summarise_each but this might be too far from our existing approach to fit in naturally.

Metadata

Metadata

Assignees

No one assigned

    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