-
Notifications
You must be signed in to change notification settings - Fork 991
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
first on empty DT should return empty DT #3858
Comments
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. |
The text was updated successfully, but these errors were encountered: