0
votes

I want to make a data frame which has the mean and median of friend_count variable which is from another data frame 'pf' by the function group_by() and summarise().

But when I try this command, the result is like below, showing the mean and median of the whole column of friend_count without grouping by age.

Please help!

library(dplyr)

pf.fc_by_age <- pf %>% group_by(age) %>%
              summarise(friend_count_mean = mean(friend_count),
                        friend_count_median = median(friend_count))
pf.fc_by_age
friend_count_mean friend_count_median
  1 196.3508 82
1
may be you loaded plyr as well. Use %>% dplyr::summarise(friend_count_mean=akrun
So simple!! Thanks a lot:)Jean
@Jean this is why some advice to use the syntax package::function() instead of only function(). While you might have other bugs, it would not be because of package conflicts/masking ;)DJV

1 Answers

-1
votes

I just have the same problem. Later on, I realised that the package plyr may be conflicted with tidyverse. When I loaded only tidyverse and avoided using plyr which solved my problem.