Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upfirst on empty DT should return empty DT #3858
Comments
jangorecki
commented
Sep 11, 2019
|
|
|
I was recently struggling with a similar question in
Curious to hear your reasoning as to which of them is better. |
|
Definitely 0 groups of any rows. 1 group of 0 rows make sense for a grand total summary where we are applying reduce function without any actual grouping. Related subject are grouping sets: rollup, cube d = data.table(grp=character(), val=numeric())
groupingsets(d, by="grp", sets=list(character()), j=.(sum=sum(val), mean=mean(val), len=length(val)))
# grp sum mean len
# <char> <num> <num> <int>
#1: <NA> 0 NaN 0
d = data.table(grp="a", val=1)
groupingsets(d, by="grp", sets=list(character()), j=.(sum=sum(val), mean=mean(val), len=length(val)))
# grp sum mean len
# <char> <num> <num> <int>
#1: <NA> 1 1 1
|
|
So, is there a difference between grouping by an empty vector (such as in your example with grouping sets), and having no |
|
@st-pasha generally the same as we would run it outside of data.table
extra warning inside dt occurs due to different length of results |
|
@jangorecki Then why
Or is it because |
|
there is no
Latter will always expand to a 1 element vector. We decided to wrap to head/tail. |