Using summarise() and group_by() in RStudio


#1

Hello! I am following along in an online textbook on how to use summarise / group_by. I came across the following from the nycflights13 data package:

by_day <- group_by(flights, year, month, day)
summarise(by_day, delay = mean(dep_delay, na.rm = TRUE))

In the textbook, it should yield the following:

#> Source: local data frame [365 x 4]_
#> Groups: year, month [?]_
#> _
#>    year month   day delay_
#>   <int> <int> <int> <dbl>_
#> 1  2013     1     1 11.55_
#> 2  2013     1     2 13.86_
#> 3  2013     1     3 10.99_
#> 4  2013     1     4  8.95_
#> 5  2013     1     5  5.73_
#> 6  2013     1     6  7.15_
#> # ... with 359 more rows_

Instead, I get this................................

delay
1 12.63907

Further on in the textbook, I came across the following using the same nycflights13 data package:

by_dest <- group_by(flights, dest)
delay <- summarise(by_dest,
  count = n(),
  dist = mean(distance, na.rm = TRUE),
  delay = mean(arr_delay, na.rm = TRUE)
)
delay <- filter(delay, count > 20, dest != "HNL")

In the console, I get this.........................................................................

by_dest <- group_by(flights, dest)
> delay <- summarize(by_dest,
+   count = n(), 
+   dist = mean(distance, na.rm = TRUE), 
+   delay = mean(arr_delay, na.rm = TRUE)
+ )
Error: This function should not be called directly
> 
> delay <- filter(delay, count > 20, dest != "HNL")
Error in filter(delay, count > 20, dest != "HNL") : 
  object 'delay' not found

I updated all my packages but I cannot get past this point in the online book! I would appreciate any assistance and thank you in advance.
--G


#2

Something messed up with your libraries? Restart R, reload dplyr, repeat?


#3

That worked exactly as you said! Much appreciated.


split this topic #4

5 posts were split to a new topic: 'nycflights13' package is not found


closed

This topic has been closed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.
#9