我想要数据框中每个组的计数和比例(所有元素)(过滤后)。此代码生成所需的输出:
@RequestMapping("/processForm")
public String processForm(@RequestParam("testParam") String title,
Model model){
return "formResult";
}
<form action="processForm" method="GET" >
<input type="text" name="hello" />
<input type="submit" />
</form>
是否有优雅的解决方案可以避免library(dplyr)
df <- data_frame(id = sample(letters[1:3], 100, replace = TRUE),
value = rnorm(100))
summary <- filter(df, value > 0) %>%
group_by(id) %>%
summarize(count = n()) %>%
ungroup() %>%
mutate(proportion = count / sum(count))
> summary
# A tibble: 3 x 3
id count proportion
<chr> <int> <dbl>
1 a 17 0.3695652
2 b 13 0.2826087
3 c 16 0.3478261
和第二ungroup()
步骤。类似的东西:
summarize()
我在文档中找不到这样的功能,但我必须遗漏一些明显的东西。谢谢!