RStudios - Dplyr - Using aggregation, How do I get an output similar to the guide I'm following?

Viewed 35

I'm trying to do some twitter analysis using r studios and I came across a certain section of the guide where it aggregates a few columns together. Where I group the persons name, and summarise the mean of the users followers and friends. On the guide it shows this

Pic 1

However, when I try to repeat the exact same code on to my r studios, It instead, shows me the following output. Why doesn't it show the "screen_name" column and it somehow takes the mean of all the rows?

Pic 2 Pic 3

1 Answers

It is possible that plyr also got loaded along with dplyr and the plyr::summarise masked the dplyr::summarise

library(dplyr)
iris %>% 
    group_by(Species) %>%
    plyr::summarise(Sepal.Width = mean(Sepal.Width))
 # Sepal.Width
 #1    3.057333

An option is to either do this on a fresh R session with dplyr only loaded or use dplyr:: explicitly to avoid getting masked

iris %>% 
     group_by(Species) %>% 
     dplyr::summarise(Sepal.Width = mean(Sepal.Width), .groups = 'drop')
# A tibble: 3 x 2
#  Species    Sepal.Width
#  <fct>            <dbl>
#1 setosa            3.43
#2 versicolor        2.77
#3 virginica         2.97
Related