我有一个从 REDCap 中提取的数据框,我已经在 RStudio 中导入了 CSV。列出唯一的参与者 ID,然后列出事件。我需要列出每个重复事件的数量,例如,acute_event_infect_arm_4 表示 1010002 是第一个拒绝事件,然后 _4b 是第二个事件,_4c 是第三个,依此类推。
我需要为跟进、拒绝和 CMV/EBV 事件执行此操作
这是具有 3 个 id 的数据帧的小快照(实际 df 有 1000 个 id)
structure(list(id = c(1010002, 1010002, 1010002, 1010002, 1010002,
1010002, 1010002, 1010002, 1010002, 1010002, 1010002, 1010002,
1010002, 1010002, 1010002, 1010002, 1010006, 1010006, 1010006,
1010006, 1010006, 1010006, 1010006, 1010006, 1010006, 1010006,
1010006, 1010008, 1010008, 1010008, 1010008, 1010008, 1010008,
1010008, 1010008, 1010008, 1010008, 1010008), redcap_event_name =
c("pre_transplant_arm_4",
"transplant_arm_4", "transplant_2_arm_4", "end_of_followup_fo_arm_4",
"last_encounter_arm_4", "acute_event_reject_arm_4",
"acute_event_reject_arm_4b",
"acute_event_infect_arm_4", "acute_event_infect_arm_4b",
"acute_event_infect_arm_4c",
"acute_event_infect_arm_4d", "acute_event_infect_arm_4e",
"acute_event_infect_arm_4f",
"acute_event_infect_arm_4g", "acute_event_cmvebv_arm_4",
"acute_event_cmvebv_arm_4b",
"pre_transplant_arm_4", "transplant_arm_4", "1_month_followup_arm_4",
"2_year_followup_arm_4", "last_encounter_arm_4", "acute_event_reject_arm_4",
"acute_event_reject_arm_4b", "acute_event_infect_arm_4",
"acute_event_infect_arm_4b",
"acute_event_infect_arm_4c", "acute_event_cmvebv_arm_4",
"pre_transplant_arm_4",
"transplant_arm_4", "3_month_followup_arm_4", "6_month_followup_arm_4",
"1_year_followup_arm_4", "2_year_followup_arm_4", "3_year_followup_arm_4",
"last_encounter_arm_4", "acute_event_reject_arm_4",
"acute_event_infect_arm_4",
"acute_event_cmvebv_arm_4")), row.names = c(NA, -38L), class = c("tbl_df",
"tbl", "data.frame"))
这是我需要在 redcap_repeat 列中添加的内容
@akrun 请在下面提供一些示例(缺少粗体红色)