I have been working with the tsibble
package and I can't get how is the proper way to remove the time component from the aggregation result.
So in the following dataset, I want to have the mean trips by Region and State. Is the proper way to convert the tsibble
to a tibble
(it might be, I am just not sure) or is there some option that I am missing to achieve the aggregation?
library(tsibble)
library(dplyr)
tourism %>% group_by(Region, State) %>% summarise(Mean_trips = mean(Trips))
# A tsibble: 6,080 x 4 [1Q]
# Key: Region, State [76]
# Groups: Region [76]
Region State Quarter Mean_trips
<chr> <chr> <qtr> <dbl>
1 Adelaide South Australia 1998 Q1 165.
2 Adelaide South Australia 1998 Q2 112.
3 Adelaide South Australia 1998 Q3 148.
## This is not what I want, this is what I want:
tourism %>% as_tibble %>% group_by(Region, State) %>% summarise(Mean_trips = mean(Trips))
# A tibble: 76 x 3
# Groups: Region [76]
Region State Mean_trips
<chr> <chr> <dbl>
1 Adelaide South Australia 143.
2 Adelaide Hills South Australia 7.18
as_tibble
is the correct way to do that as suggested when doingtourism %>% select(-Quarter)
– Metatarsal