Warning message for dplyr package when trying to utilize the summarise_each function

Hi,
This problem has been bothering me for about two days now. You see, I'm following a tutorial on Youtube that teaches how to use the dplyr package. Since the video is from 2014, some of the codes have changed. I kept getting warnings for these lines of codes:
flights %>%
group_by(UniqueCarrier) %>%
summarise_each(funs(min(., na.rm=TRUE), max(., na.rm=TRUE)), matches("Delay"))

The warning that I got says this:
funs() is soft deprecated as of dplyr 0.8.0
*Please use a list of either functions or lambdas: *

  • Simple named list: *

  • list(mean = mean, median = median)*

  • Auto named with tibble::lst(): *

  • tibble::lst(mean, median)*

  • Using lambdas*

  • list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))*

The code that I'm trying to get it working is suppose to calculate the maximum and minimum arrival and departure delays. Any help is appreciated!

summarise_at() in the modern equivalent of summarise_each(). As explained in the warning, we now need to pass a list of summary functions instead of using funs().

Here's your code reworked using lambda functions. I guess you're using the nycflights13 dataset.

library(tidyverse)
#> Warning: package 'forcats' was built under R version 3.6.3
library(nycflights13)
#> Warning: package 'nycflights13' was built under R version 3.6.3

flights %>%
  group_by(carrier) %>%
  summarise_at(vars(matches("delay")), list(~min(., na.rm = TRUE), ~max(., na.rm = TRUE)))
#> # A tibble: 16 x 5
#>    carrier dep_delay_min arr_delay_min dep_delay_max arr_delay_max
#>    <chr>           <dbl>         <dbl>         <dbl>         <dbl>
#>  1 9E                -24           -68           747           744
#>  2 AA                -24           -75          1014          1007
#>  3 AS                -21           -74           225           198
#>  4 B6                -43           -71           502           497
#>  5 DL                -33           -71           960           931
#>  6 EV                -32           -62           548           577
#>  7 F9                -27           -47           853           834
#>  8 FL                -22           -44           602           572
#>  9 HA                -16           -70          1301          1272
#> 10 MQ                -26           -53          1137          1127
#> 11 OO                -14           -26           154           157
#> 12 UA                -20           -75           483           455
#> 13 US                -19           -70           500           492
#> 14 VX                -20           -86           653           676
#> 15 WN                -13           -58           471           453
#> 16 YV                -16           -46           387           381

Created on 2020-03-06 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.