When I run the following command I get an annoying message that says: summarise() ungrouping output (override with .groups argument)
.
I was wondering how I can eliminate this message in my data below?
library(tidyverse)
hsb <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')
ave_cluster_n <- as_vector(hsb %>% dplyr::select(sch.id) %>% group_by(sch.id) %>% summarise(n=n()) %>% ungroup() %>% dplyr::select(n))
# `summarise()` ungrouping output (override with `.groups` argument) # How to eliminate this message
This can be managed as a pkg option:
library(tidyverse)
options(dplyr.summarise.inform = FALSE)
... and you don't see those messages anymore
We can specify the .groups
argument in summarise
with different options if we want to avoid getting the message. Also, to extract as a vector
, in the tidyverse, there is pull
to pull the column
library(dplyr)
hsb %>%
dplyr::select(sch.id) %>%
group_by(sch.id) %>%
summarise(n=n(), .groups = 'drop') %>%
pull(n)
Or another option is to bypass the group_by/summarise
altogether and use count
hsb %>%
count(sch.id) %>%
pull(n)
Or with tally
hsb %>%
group_by(sch.id) %>%
tally()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With