summarise() regrouping output 警告

本文探讨了在R中使用dplyr包时summarise()函数产生的regrouping output警告。警告指出,返回的tibble只保留了homeword的分组属性,而忽略了species。尽管更改默认行为可能影响现有代码,但在dplyr 1.0.0中,将显示一条消息以更明确地暴露默认行为。为控制分组并消除消息,可以使用新的group_by参数,它有四个可能的值:drop_last(默认行为)、drop_all(取消所有分组)、inherit(保留输入的分组)和rows(每行作为独立组)。
摘要由CSDN通过智能技术生成

summarise() regrouping output 警告

这里讨论的是return的属性,而不是group_by本身。以下面代码为例,summarise之后给出的警告信息是指,这里return的tibble的atrribute中group_by参数只有homeword,没有species。也就是说,返回一个按照homeword这个level进行group_by的tibble,species被drop掉了。

如果设置.groups = "drop",返回的是一个不带任何group level的tibble。

Unfortunately, it would be very difficult to change this default now because a lot of code probably relies on it. Instead, we’re doing the next best thing: exposing the default behaviour more explicitly and making it easier to change. In dplyr 1.0.0, the code above will display a message telling you how the result has been grouped:

homeworld_species <- starwars %>% 
  group_by(homeworld, species) %>% 
  summarise(n = n())
#> `summarise()` regrouping output by 'homeworld' (override with `.groups` argument)
</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值