Skip to content

Count by list columns #1597

@MichaelChirico

Description

@MichaelChirico

Perhaps this is intentional, but it seems to me a more natural solution to this question on SO would be:

shoppinglists[ , if (.N>=3) 
  .(triplet = combn(items, 3, simplify=FALSE)), 
  by=consumer][ , .N, by=triplet][order(-N)]

But if we try and use the list column in by we get an error:

Error in`` [.data.table(shoppinglists[, if (.N >= 3) list(triplet = combn(items,`:
The items in the`by`or`keyby`list are length`(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3)`. Each must be same length as rows in`x`or number of rows returned by`i` (18).

As cryptic as this error is, I think by is having trouble identifying unique lists (perhaps this is by design).

Is there no way to do use a list column in by?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions