r - 按日期和潜在客户的行动重新排列我的数据集
问题描述
我正在以这种方式构建的数据库上研究 R:
Lead Date state
1 01/01/2020 active
1 02/01/2020 standby
2 01/01/2020 standby
2 02/01/2020 active
2 03/01/2020 offer won
3 01/01/2020 standby
3 02/01/2020 active
... ... ...
而且我想要类似的东西,使用日期来安排潜在客户的状态:
Lead Chronology by date
1 active;standby
2 standby;active;offer won
3 standby;active
... ...
解决方案
假设您的数据是一个名为 的 data.frame df
,您可以使用tidyverse
包轻松完成此操作。
library(dplyr)
library(stringr)
df %>%
group_by(Lead) %>%
arrange(Date) %>%
summarize(Chronology_by_date = str_c(state, collapse = ";"))
推荐阅读
- php - 如何在 PHP 中显示嵌套的 JSON 数据
- rabbitmq - 来自 Flink 的 RabbitMQ 中未确认的消息
- sql - 如何根据事件类型数据填充行
- java - 如何随着时间的推移隐藏/显示 JPanel(JAVA、图形、动画)
- swift - 快速多行字符串的缩进
- android - 连接到相机 0 时出现 Android 相机错误
- sql-server - 使用公共 IP 的多台服务器的 SQL 复制?
- locust - 用 URL 以外的东西命名任务
- python - 超参数调整 (Hyperas) 和流水线预处理的交叉验证
- angular - Rxjs catchError 导致 TypeScript 类型错误