-
Notifications
You must be signed in to change notification settings - Fork 982
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 #1757] Add drop to [.data.table, and "dontmove" to not put group columns first #648
Comments
This points here too : |
+1 for support of library(data.table)
x = data.table(a=c(2,5))
x[, sum(a), drop=FALSE]
# could translate to
x[, .(sum(a))] This is minor thing but increase consistency as type returned won't be dependent on the existence of |
@jangorecki I don't understand why in the given example |
@eantonya When I'm just passing |
See also #1188 |
strikes again due to losing autonaming for |
I would like to suggest a use case for library(data.table)
d = data.table(id1=c(1L,1L,1L,2L,2L), id2=c(6L,6L,7L,7L,7L), v1=c(1,2,3,4,5))
d[id1==1L]
# id1 id2 v1
#1: 1 6 1
#2: 1 6 2
#3: 1 7 3
d[id1==2L]
# id1 id2 v1
#1: 2 7 4
#2: 2 7 5
d[id1==1L, drop=TRUE]
# id2 v1
#1: 6 1
#2: 6 2
#3: 7 3
d[id1==2L, drop=TRUE]
# v1
#1: 4
#2: 5 This may be seen as something that makes it difficult to predict what the dimensions of the answer will be but there are use cases for that. I had exactly such use case, for which I used the following helper. drop.data.table = function(x, cols) {
ans = data.table:::shallow(x)
un = sapply(cols, function(col) uniqueN(x[[col]]))
rm = names(un)[un <= 1L]
if (length(rm)) set(ans, NULL, rm, NULL) # Rdatatable/data.table#4086
ans
} The tricky part is how to distinguish identity columns from measures, that seems to be quite impossible without requiring user to provide such metadata. In the helper above Also worth to note it is basically what |
Submitted by: Matt Dowle; Assigned to: Nobody; R-Forge link
http://r.789695.n4.nabble.com/Syntax-ag-M-age-age-tp4313006p4313006.html
It wouldn't just build the table and extract the vector at the end, but only construct the vector in the first place; i.e., dogroup.c would need to switch on drop and not populate iby when drop=TRUE.
The text was updated successfully, but these errors were encountered: