Skip to content
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

dplry::summarise leaves grouped_ts when dplyr::group_by'ing over multiple variables #274

Open
psarka opened this issue Feb 22, 2022 · 0 comments

Comments

@psarka
Copy link

psarka commented Feb 22, 2022

Consider the example from the tsibble index_by reference and it's modified version:

tourism %>%
  index_by(Year = ~ year(.)) %>%
  group_by(Region, State) %>%
  summarise(Total = sum(Trips))
# A tsibble: 1,520 x 4 [1Y]
# Key:       Region, State [76]
# Groups:    Region [76]
   Region   State            Year Total
   <chr>    <chr>           <dbl> <dbl>
 1 Adelaide South Australia  1998 2226.
 2 Adelaide South Australia  1999 2218.
 3 Adelaide South Australia  2000 2418.
> tourism %>%
+   index_by(Year = ~ year(.)) %>%
+   group_by(Region) %>%
+   summarise(Total = sum(Trips))
# A tsibble: 1,520 x 3 [1Y]
# Key:       Region [76]
   Region    Year Total
   <chr>    <dbl> <dbl>
 1 Adelaide  1998 2226.
 2 Adelaide  1999 2218.
 3 Adelaide  2000 2418.

In the first case:

  • grouping and summing happened over (Year, Region, State)
  • result is grouped_ts with Region as a grouped variable

In the second case:

  • grouping and summing happened over (Year, Region)
  • result ir tbl_ts

This is not very intuitive, as summary function seems to be "dropping" 2 (?) grouping variables. I expected it to either drop only Year, resulting in grouped_ts in both cases, or to "drop" all variables, resulting in tbs_ts in both cases. Not sure if this is a bug, but even if it isn't, I would have liked to have it mentioned somewhere (together with dplyr::ungroup which I guess I need to use in the first case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant