汇总用户类型
既然可以使用 count() 这个封装函数,为什么还要在分组汇总中手动统计行数?有时您需要更细致的汇总,而在同时包含数值型与分类型汇总的分组统计中,学会如何计算计数会很有用。
本练习是课程的一部分
R 文本分析入门
练习说明
- 按用户是否通过认证对
twitter_data分组。 - 计算每类用户的平均粉丝数,将新列命名为
avg_followers。 - 统计认证与未认证用户的数量,为保持一致,将新列命名为
n。
交互式实操练习
通过完成这段示例代码来试试这个练习。
library(tidyverse)
twitter_data %>%
# Group by whether or not a user is verified
___(___) %>%
summarize(
# Compute the average number of followers
___ = ___,
# Count the number of users in each category
___ = ___
)