0

Can someone help me calculate the average daily steps for every location from the tibble below? This is the code I have so far. The final tibble should only contain the location and daily average steps.

  group_by(location, date) %>% 
  summarise(daily_count = sum(count))
step_count_daily 

> step_count_daily
# A tibble: 364 x 3
# Groups:   location [4]
   location date       daily_count
   <chr>    <date>           <dbl>
 1 Austin   2019-01-15       5146 
 2 Austin   2019-01-16       9138 
 3 Austin   2019-01-17       4000 
 4 Austin   2019-01-18       2980.
 5 Austin   2019-01-19       7287 
 6 Austin   2019-01-20       6567 
 7 Austin   2019-01-21       7538.
 8 Austin   2019-01-22      15579 
 9 Austin   2019-01-23      15362 
10 Austin   2019-01-24       6923 
# … with 354 more rows


#This is the tibble

 date_time           date       count location 
   <dttm>              <date>     <dbl> <chr>    
 1 2019-01-01 09:00:00 2019-01-01   764 Melbourne
 2 2019-01-01 10:00:00 2019-01-01   913 Melbourne
 3 2019-01-02 00:00:00 2019-01-02     9 Melbourne
 4 2019-01-02 10:00:00 2019-01-02  2910 Melbourne
 5 2019-01-02 11:00:00 2019-01-02  1390 Melbourne
 6 2019-01-02 12:00:00 2019-01-02  1020 Melbourne
 7 2019-01-02 13:00:00 2019-01-02   472 Melbourne
 8 2019-01-02 15:00:00 2019-01-02  1220 Melbourne
 9 2019-01-02 16:00:00 2019-01-02  1670 Melbourne
10 2019-01-02 17:00:00 2019-01-02  1390 Melbourne

#The output should look like this

#> # A tibble: 4 x 2
#>   location      avg_count
#>   <chr>             <dbl>
#> 1 Austin            7738.
#> 2 Denver           12738.
#> 3 Melbourne         7912.
#> 4 San Francisco    13990.
Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

1

To get a dataframe containing location and the average across all days of steps:

step_count_daily %>%
group_by(location) %>%
summarise(mean_steps = mean(count))
Elle
  • 998
  • 7
  • 12