如何取双打向量的平均值

how to take a mean of a vector of doubles

library(nycflights13)
flights = nycflights13::flights

flights %>% select(arr_delay, month) %>% group_by(month) %>% filter(!is.na(arr_delay))

我的目标是获取每个月的平均到达延迟时间,但每次尝试取平均值时,我都会出错

mean中有一个na.rm参数,所以不需要filter,而是在summarise

中使用mean
library(dplyr)
flights %>% 
    select(arr_delay, month) %>%
    group_by(month) %>% 
    summarise(Mean = mean(arr_delay, na.rm = TRUE))

-输出

# A tibble: 12 × 2
   month   Mean
   <int>  <dbl>
 1     1  6.13 
 2     2  5.61 
 3     3  5.81 
 4     4 11.2  
 5     5  3.52 
 6     6 16.5  
 7     7 16.7  
 8     8  6.04 
 9     9 -4.02 
10    10 -0.167
11    11  0.461
12    12 14.9