r - 命名 dplyr 计数列
问题描述
根据https://dplyr.tidyverse.org/reference/tally.html,运行以下代码:
# Change the name of the newly created column:
species <-
starwars %>%
count(species, homeworld, sort = TRUE, name = "n_species_by_homeworld")
species
应该产生:
#> # A tibble: 58 x 3
#> species homeworld n_species_by_homeworld
#> <chr> <chr> <int>
#> 1 Human Tatooine 8
#> 2 Human <NA> 5
#> 3 Human Naboo 5
#> 4 Gungan Naboo 3
#> 5 Human Alderaan 3
#> 6 <NA> <NA> 2
#> 7 <NA> Naboo 2
#> 8 Droid <NA> 2
#> 9 Droid Tatooine 2
#> 10 Human Corellia 2
#> # … with 48 more rows
但是,我得到:
# A tibble: 58 x 4
species homeworld name n
<chr> <chr> <chr> <int>
1 Human Tatooine n_species_by_homeworld 8
2 Human Naboo n_species_by_homeworld 5
3 Human NA n_species_by_homeworld 5
4 Gungan Naboo n_species_by_homeworld 3
5 Human Alderaan n_species_by_homeworld 3
6 Droid Tatooine n_species_by_homeworld 2
7 Droid NA n_species_by_homeworld 2
8 Human Corellia n_species_by_homeworld 2
9 Human Coruscant n_species_by_homeworld 2
10 Kaminoan Kamino n_species_by_homeworld 2
# ... with 48 more rows
帮助?
我在跑:
R 版本 3.5.0 (2018-04-23)
平台:i386-w64-mingw32/i386(32位)
- 在以下环境下运行:Windows >= 8 x64(内部版本 9200)
解决方案
推荐阅读
- php - 循环期间的服务器响应(状态更新)
- c# - WPF中列表视图的性能缓慢
- c++ - 正则表达式多次匹配相同的模式
- ios - 是否可以检测到将远程通知添加到通知中心的时刻?
- python - 有没有办法使用条件中的多种数据类型来过滤 Python 中的列?
- css - 使用重复(自动填充)时如何限制列宽
- sql-server - 当前记录与先前记录之间的时间差(带有滞后变量和案例语句)
- c++ - 将 NDEF 记录有效负载转换为 EthernetClient print() 的字符串
- r - 有没有合适的方法来聚类时间序列,其中只有四个值是可能的(0,1,2,4)并且长度不固定?
- ruby-on-rails - 如何在不更新所有值而只更新已更新的值(即加密货币)的情况下更新我的抓取数据