了解理货(sort = TRUE)

用户名

所以之前有这段代码:

flights %>%
  group_by(dest) %>%
  summarise(arr_delay = mean(arr_delay, na.rm = TRUE),
  n = n()) %>%
arrange(desc(arr_delay))

我明白这段代码。但是下面的代码显示:

flights %>%
  group_by(carrier, flight, dest) %>%
  tally(sort = TRUE) %>% # Save some typing
  filter( n == 365)

所以这段代码我不明白

tally(sort = TRUE)

当它说保存一些键入内容时,它究竟保存了什么?我知道tally(sort = TRUE)replaces summerise(n = n()),但是它如何“保存键入”以及如何彼此关联?如果有人可以细分我tally(sort = TRUE),将不胜感激!

大卫·阿伦堡

我还远不是dplyr专家,但由于没人愿意回答,因此我会尝试一下。因此,从理货单据中获取的所有信息只是为您提供每组的频率。如果您嵌入两个tallys,它们将只是sum频率,因此例如:

library(dplyr)
tally(group_by(CO2, Plant)) 

#    Plant n
# 1    Qn1 7
# 2    Qn2 7
# 3    Qn3 7
# 4    Qc1 7
# 5    Qc3 7
# 6    Qc2 7
# 7    Mn3 7
# 8    Mn2 7
# 9    Mn1 7
# 10   Mc2 7
# 11   Mc3 7
# 12   Mc1 7

只是基数R table

table(CO2$Plant)
# Qn1 Qn2 Qn3 Qc1 Qc3 Qc2 Mn3 Mn2 Mn1 Mc2 Mc3 Mc1 
#   7   7   7   7   7   7   7   7   7   7   7   7 

tally(tally(group_by(CO2, Plant)))
#    n
# 1 84

只是

sum(table(CO2$Plant))
# [1] 84

要么

tally(CO2)
#   n
#1 84

要么

nrow(CO2)
# [1] 84

所以你的问题,

flights %>%
  group_by(carrier, flight, dest) %>%
  tally(sort = TRUE) %>% # Save some typing
  filter( n == 365)

手段

Take data set "flights" 
 group it by "carrier", "flight" and "dest" columns
 give me the frequencies of these combinations and sort them by frequecy
 return only the combinations that their frequency equals to 365

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

了解理论级联操作

了解inplace = True

了解setPresistanceEnabled(true)和keepSynced(true)

进一步了解setRetainInstance(true)

了解 log_uniform_candidate_sampler 中的 true_classes

VBA - .Sort 方法将数据转换为 TRUE

布尔身份== True与True

布尔身份== True与True

如果不是true(!true)

了解Resx文件中的Localization = True track会进行哪些属性更改

不了解 set 迭代是如何工作的,期望为 true 但返回 false

为什么在Python中`(True,True,True)== True,True,True`不是True?

false或true!= true或false!= true || 错误的

[True] 中的 [True] 中的 True 输出:False

为什么lodash`_.all([true,true,true],true);`返回`false`?

将10111(数字)转换为true,false,true,true,true

“ parent,true”或“ null,true”的功能

为什么“ True and〜True” -2?

为什么 Python3 中的 True, True, True == (True, True, True) 给出 o/p True, True, False?

Python 3.9 区别 list.sort(reverse=True) 和 list.reverse()

是否有充分的理由将sort与index.return = TRUE而不是order一起使用?

javascript 中 true && true && true && false && true && true && true 的结果是什么?

我不了解inflate方法的第三个参数的true与false之间的主要区别

谁能解释为什么True,True ==(True,True)的输出是(True,False)?

当 {a statement that is equal to True} == True 评估为 false 时,为什么 True == True 评估为 True?

关于sqlalchemy中的unique = True和(unique = True,index = True)

“in”操作符链接(True in [True] in [True] OUTPUT: False )

(true!= false!= true)与(false!= true!= false)有何区别?

处理货币价值