Repository navigation
Returning only groups #1269
Description
Activity
Would it be sensible to have
DT[, list(), by = x]perform this kind of grouping; that is, as a special case wherejis an empty list? Or is it expected that this would provide results identical toDT[, c(), by = x]in the development version ofdata.table?Or, alternatively, the syntax
DT[, by = x]could implicitly collapse over the grouping variablex? Right now it seems like that is a no-op.@kevinushey, IIRC we'd like for
DT[, , by = .]andDT[by=.]to mimicDT[, .SD, by=.]. Just because it makes more sense than just returning the groups (for data.table syntax).DT[, .(), by=.]andDT[, list(), by=.]doesn't feel quite right to me, yet, as well. It seems like a very rare operation, but we should be able to do this. Will keep thinking. More suggestions of course welcome!Related issue - #1242
It is possible using
DT[, unique(.SD), .SDcols=.]. TheDT[, list(), by=.]would be fine but thejof length 0 makes some inconsistency with non-0 rows returned value. MaybeDT[, list(.), by=.]would be better? currently just duplicates the column(s), that could be handled.Some other thoughts:
DT[, NULL, by = x]: TreatNULLspecially when a group has been specified?DT[, .NULL, by = x]: Use a special dot symbol as a proxy for 'no column(s) to generate', similar in spirit to the other.Ivariables?DT[, groups = x]: Add a new parameter that performs grouping and returns the groupeddata.table; operates the same asbybut does not accept ajexpression?
Of the options so far, I like
DT[, .(), by = ...]the most - and the more I stare at it, the more it seems to be perfectly suited for this job.Reacted by Pasha StetsenkoI like DT[, .(), by = ...]
+1, seems as the most natural option to me as well.
Personally, I think
DT[keyby=...]is most natural and easiest to read (byandkeybyshould be interchangeable here).Since you don't want
j, leaving it out seems natural. Also, it leaves open the possibility for adding aniargument, which could be handy. (For example you could want "all names / email combos that didn't get a response, except known spam addresses.)Reacted by Jan Gorecki and Vitalie SpinuLinking to discussion here: http://stackoverflow.com/questions/36270046/is-it-possible-to-return-a-data-table-without-j also #1245
I like the @geneorama proposal, there is another issue on handling that #1105
Could eventually be defined as
.SDcols=NULL,.SDcols=character().Actually, there is a simple syntax for doing this:
DT[, .(x = unique(x))]@aradev In current implementation, this is much slower than
DT[ , TRUE, by = x].
From tidyverse/dplyr#1073 (comment)
Currently, there's no way of returning just the groups: