0

I'd like to compute the average distance of the flights which have reached a destination by using the flights data frame.

Here is my code :

library(nycflights13)
destinations <- group_by(flights, dest)
summarise(destinations, avg_distance = mean(distance))

Here is the result :

   planes
1 1039.913

And I like to have something like that:

dest | avg_distance 
IAH  | 1405
ORD  | 890

How could I do that with dplyr?

Ricol
  • 377
  • 4
  • 9
  • 22
  • 1
    Try `dplyr::summarise(destinations, avg_distance = mean(distance))` instead. You probably have plyr loaded as well (after you loaded dplyr) – talat Feb 24 '15 at 11:50
  • @docendo discimus : you're right. It was because of the plyr package. Could you please help me to understand why there was a conflict ? – Ricol Feb 24 '15 at 12:16
  • 1
    The conflict occurs because plyr and dplyr both have functions with identical names (mutate and summarise). So by default, the function will be used from the package that was loaded last, according to my understand. There is also a warning when you load plyr after dplyr that tells you this. So either load dplyr after plyr or only use one at a time or specify the package to be used explicitly – talat Feb 24 '15 at 12:16

0 Answers0