所以之前有这段代码:
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
专家,但由于没人愿意回答,因此我会尝试一下。因此,从理货单据中获取的所有信息只是为您提供每组的频率。如果您嵌入两个tally
s,它们将只是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] 删除。
我来说两句