我有一个数据框,已对其进行分组,然后按多个字段进行汇总:
gn %>%
group_by(`_source.time`) %>%
summarize(
leads_TRUE = sum(`_source.lead` == TRUE),
leads_FALSE = sum(`_source.lead` == FALSE),
leads_T_conv = sum(leads_TRUE) / nrow(gn),
leads_F_conv = sum(leads_FALSE) / nrow(gn),
overall_conv = sum(leads_T_conv + leads_F_conv) / 2
) %>%
ungroup()
这给了我
# A tibble: 64 x 6
`_source.time` leads_TRUE leads_FALSE leads_T_conv leads_F_conv overall_conv
<date> <int> <int> <dbl> <dbl> <dbl>
1 2018-05-14 8 89 0.00161 0.0179 0.0587
2 2018-05-15 31 68 0.00623 0.0137 0.0587
3 2018-05-16 28 85 0.00563 0.0171 0.0587
我如何计算发生的单个日期(_source.time
)的数量并将其列为一列(date_count
)?
我正在寻找的输出将与
相同> gn$`_source.time` %>% table %>% as.matrix
[,1]
2018-05-14 97
2018-05-15 99
2018-05-16 113
,以便每个日期都可以统计在分组数据框中出现的次数。
答案 0 :(得分:1)
您可以使用// view templete
<!DOCTYPE html>
<html>
<head>
<title>$data->title</title>
</head>
<body>
<div>$data->product</div>
</body>
</html>
:
n_distinct