Skip to content

[R-Forge #5289] .I should always reflect the original row local #539

Closed

Description

@arunsrinivasan

Submitted by: Michele Carriero; Assigned to: Nobody; R-Forge link

Please consider the following:

dt <- data.table(a=sample(letters, 100, T), b=rnorm(100))
dt[ a=="c", list(.N, .I)]
   N .I
1: 4  1
2: 4  2
3: 4  3
4: 4  4

dt[a=="c", list(.N, .I), by=a]
   a N .I
1: c 4 54
2: c 4 67
3: c 4 71
4: c 4 86

The first statement subsets the table first and then calculates locations. The second shows the original location of all rows having a=="c".

Unless there are reasons (which I'm currently missing) for which the above needs to happen, I think that both expressions should give the second result.

Regards,
Michele.

Activity

  1. jangorecki commented on Apr 5, 2020

    @jangorecki
    Member

    closing as duplicate of #2598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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