Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 1 comment
Closed

Comments

@arunsrinivasan
Copy link
Member

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.

@jangorecki
Copy link
Member

closing as duplicate of #2598

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

No branches or pull requests

2 participants