[英]Eliminate the ungroup... message from tidyverse package
When I run the following command I get an annoying message that says: summarise() ungrouping output (override with .groups argument)
.当我运行以下命令时,我收到一条烦人的消息: 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:这可以作为 pkg 选项进行管理:
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.如果我们想避免收到消息,我们可以使用不同的选项在summarise
指定.groups
参数。 Also, to extract as a vector
, in the tidyverse, there is pull
to pull the column另外,要提取为vector
,在 tidyverse 中,有pull
来拉列
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
或者另一种选择是完全绕过group_by/summarise
并使用count
hsb %>%
count(sch.id) %>%
pull(n)
Or with tally
或与tally
hsb %>%
group_by(sch.id) %>%
tally()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.