You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be sensible to have DT[, list(), by = x] perform this kind of grouping; that is, as a special case where j is an empty list? Or is it expected that this would provide results identical to DT[, c(), by = x] in the development version of data.table?
@kevinushey, IIRC we'd like for DT[, , by = .] and DT[by=.] to mimic DT[, .SD, by=.]. Just because it makes more sense than just returning the groups (for data.table syntax).
DT[, .(), by=.] and DT[, 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!
It is possible using DT[, unique(.SD), .SDcols=.]. The DT[, list(), by=.] would be fine but the j of length 0 makes some inconsistency with non-0 rows returned value. Maybe DT[, list(.), by=.] would be better? currently just duplicates the column(s), that could be handled.
DT[, NULL, by = x]: Treat NULL specially 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 .I variables?
DT[, groups = x]: Add a new parameter that performs grouping and returns the grouped data.table; operates the same as by but does not accept a j expression?
Personally, I think DT[keyby=...] is most natural and easiest to read (by and keyby should be interchangeable here).
Since you don't want j, leaving it out seems natural. Also, it leaves open the possibility for adding an i argument, which could be handy. (For example you could want "all names / email combos that didn't get a response, except known spam addresses.)
Activity
kevinushey commentedon Aug 14, 2015
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?kevinushey commentedon Aug 14, 2015
Or, alternatively, the syntax
DT[, by = x]could implicitly collapse over the grouping variablex? Right now it seems like that is a no-op.arunsrinivasan commentedon Aug 14, 2015
@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!eantonya commentedon Aug 14, 2015
Related issue - #1242
jangorecki commentedon Aug 14, 2015
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.kevinushey commentedon Aug 14, 2015
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?eantonya commentedon Aug 14, 2015
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.vspinu commentedon Aug 27, 2015
+1, seems as the most natural option to me as well.
geneorama commentedon Mar 28, 2016
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.)mattdowle commentedon Mar 28, 2016
Linking to discussion here: http://stackoverflow.com/questions/36270046/is-it-possible-to-return-a-data-table-without-j also #1245
jangorecki commentedon Apr 13, 2016
I like the @geneorama proposal, there is another issue on handling that #1105
jangorecki commentedon Aug 2, 2016
Could eventually be defined as
.SDcols=NULL,.SDcols=character().aradev commentedon Nov 16, 2017
Actually, there is a simple syntax for doing this:
DT[, .(x = unique(x))]MichaelChirico commentedon Nov 16, 2017
@aradev In current implementation, this is much slower than
DT[ , TRUE, by = x].