【发布时间】:2021-04-18 07:16:01
【问题描述】:
我有下表,并希望在 R 中为每个唯一 ID 创建一个新列
MeetingID <- c("01", "02","03","02","04","03")
Attendee <- c("Alex","Bob","Tim","Xavier","Ana","Bob")
AttendedMonth <- c("Jan","Apr","Feb","Apri","Feb","Feb")
df <- data.frame(MeetingID, Attendee,AttendedMonth)
| MeetingID | Attendeee | AttendedMonth |
|---|---|---|
| 01 | Alex | Jan |
| 02 | Bob | Apr |
| 03 | Tim | Feb |
| 02 | Xavier | Apr |
| 04 | Ana | Feb |
| 03 | Bob | Feb |
我打算创建一个类似于矩阵的数据框,其中对于每个 MeetingID,如果与会者没有参加会议,我想标记 (0),如果与会者参加了会议,我想标记 (1)
| Attendee | 01 | 02 | 03 | 04 |
|---|---|---|---|---|
| Alex | 1 | 0 | 0 | 0 |
| Bob | 0 | 1 | 1 | 0 |
| Tim | 0 | 0 | 1 | 0 |
| Xavier | 0 | 1 | 0 | 0 |
| Ana | 0 | 0 | 0 | 1 |
【问题讨论】: