gpt4 book ai didi

r - 使用标准评估更改 dplyr::count 中的变量名称

转载 作者:行者123 更新时间:2023-12-04 18:03:26 24 4
gpt4 key购买 nike

dplyr::count_ 以标准评估方式使用时,如何更改分组变量的名称

例如,如果在最终的 tbl 中我不想要 var 名称“Species”而是“Type”:

iris %>% 
group_by("Species") %>%
count_("Species")

Source: local data frame [3 x 2]

Species n
1 setosa 50
2 versicolor 50
3 virginica 50

我还想知道 dplyr::count_ 是如何工作的以及这个表达式应该做什么?你有解释吗?

> iris %>% group_by("Species") %>% count_("x = Species")
Source: local data frame [3 x 2]

x = Species n
1 setosa 50
2 versicolor 50
3 virginica 50

谢谢!

最佳答案

好吧,我在发帖前使用了 setNames,但方式不对。这似乎是解决方案:

count_(iris, setNames("Species", "type"))

关于r - 使用标准评估更改 dplyr::count 中的变量名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31269424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com