R 计算tibble中每个位置的平均每日步数

R 计算tibble中每个位置的平均每日步数,r,average,mean,R,Average,Mean,有人能帮我计算下表中每个位置的平均每日步数吗?这是我目前掌握的代码。最终TIBLE应仅包含位置和每日平均步数 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

有人能帮我计算下表中每个位置的平均每日步数吗?这是我目前掌握的代码。最终TIBLE应仅包含位置和每日平均步数

  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.
分组人(地点、日期)%>%
总结(每日计数=总和(计数))
步骤(每天计算)
>步骤(每天计算)
#A tibble:364x3
#分组:地点[4]
地点日期每日计数
1奥斯汀2019-01-15 5146
2奥斯汀2019-01-16 9138
3奥斯汀2019-01-17 4000
4奥斯汀2019-01-182980。
5奥斯汀2019-01-197287
6奥斯汀2019-01-206567
7奥斯汀2019-01-21 7538。
8奥斯汀2019-01-22 15579
9奥斯汀2019-01-23 15362
10奥斯汀2019-01-24 6923
#…还有354行
#这是tibble
日期\时间日期计数位置
2019-01-01 09:00:00 2019-01-01 764墨尔本
2 2019-01-01 10:00:00 2019-01-01 913墨尔本
3 2019-01-02 00:00:00 2019-01-02 9墨尔本
4 2019-01-02 10:00:00 2019-01-02 2910墨尔本
5 2019-01-02 11:00:00 2019-01-02 1390墨尔本
6 2019-01-02 12:00:00 2019-01-02 1020墨尔本
7 2019-01-02 13:00:00 2019-01-02 472墨尔本
8 2019-01-02 15:00:00 2019-01-02 1220墨尔本
9 2019-01-02 16:00:00 2019-01-02 1670墨尔本
10 2019-01-02 17:00:00 2019-01-02 1390墨尔本
#输出应该如下所示
#>#tibble:4 x 2
#>位置平均计数
#>                
#>1奥斯汀7738。
#>2丹佛12738。
#>3墨尔本7912。
旧金山>4,13990。

要获取包含位置和所有步骤天数平均值的数据帧:

step_count_daily %>%
group_by(location) %>%
summarise(mean_steps = mean(count))