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

DT[, list(by_var), by = by_var) #876

Closed
matthieugomez opened this issue Oct 10, 2014 · 4 comments
Closed

DT[, list(by_var), by = by_var) #876

matthieugomez opened this issue Oct 10, 2014 · 4 comments

Comments

@matthieugomez
Copy link
Contributor

I'm not sure whether it is a bug or not ; I expected the following commands to return a data.table with the same number of rows than DT

DT <- data.table(id = c(1,1,2,2))
DT[, list(id), by=id]
DT[, list(id, .N), by=id]
@arunsrinivasan
Copy link
Member

by arguments are by default available as length=1 variables in j. The kind of operation you perform is unnecessary, as they (by arguments) are returned by default. The idea is to be able to perform operations like:

DT[, list(sum(y)*x), by=x]

without having to do x[1L].

But there's a bug that needs to be fixed #497 which is a consequence of this feature.

@matthieugomez
Copy link
Contributor Author

Thanks. I did no know that. I actually wanted to do DT[, list(id, .N), by = id]

@arunsrinivasan
Copy link
Member

!Oops.. misunderstood!

Can you explain why you wanted to do that? It'd duplicate id column.

@matthieugomez
Copy link
Contributor Author

Right - I was wrong for two reasons. the syntax is good as it is.

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

No branches or pull requests

2 participants