r - R中的字符变量分组
问题描述
我想制作一个数据框,显示按一个变量分组的字符变量的发生率,在本例中为 c2_inicio。我有如下数据:
c2_inicio usuario_inicia f_alarm
1 C2 Poniente PH903731 DELITO
2 C2 Norte C4895756 SERVICIO
3 C2 Oriente Sistema FALSA ALARMA
4 C2 Poniente Sistema FALSA ALARMA
5 C2 Norte C4895646 SERVICIO
6 C2 Centro C4895678 URGENCIAS MEDICAS
7 C2 Oriente C5PEPK86 EMERGENCIA
8 C2 Poniente C5ROGK95 FALTA CÍVICA
9 C2 Poniente Sistema FALSA ALARMA
10 C2 Poniente Sistema FALSA ALARMA
我需要这样的表:
c2_inicio incidence_user incidence_DELITO incidence_EMERGENCY
1 C2 Centro 38582 [number of DELITOS] [number of EMERGENCIES]
2 C2 Norte 76632 [...by c2_inicio]
3 C2 Oriente 77075
4 C2 Poniente 72333
5 C2 Sur 59137
6 C4i 65
我试过了:
base_c2 <- c4%>%group_by(c2_inicio)%>%summarise(incidentes=n())
但只计算每个 c2_inicio 的观察总数。
我怎样才能做到这一点?先进的Thx ;)
解决方案
推荐阅读
- python - 你如何用 Python 模拟 Instagram 上的无限滚动?
- macos - pycurl macOS 安装问题
- java - 使用 Flyway 进行延迟数据库迁移
- java - 如何在 Kotlin 中实现 Serializable 使其在 Java 中也能工作?
- r - 使用多个模式和多个指定替换链接字符串操作
- webview - 编译 uwp-community-toolkit dll 问题
- python - 在python中查找三个重叠集中的增量
- java - 使用 Kafka Connect API 将对象从 REST API 插入到 Kafka
- python - 如何将张量视为图像?
- java - 防止类卸载,java