【发布时间】:2021-06-20 04:52:10
【问题描述】:
这是我的数据集:
df <- data.frame(PatientID = c("3454","3454","3454","345","345","345"), date = c("05/01/2001", "02/06/1997", "29/03/2004", "05/2/2021", "01/06/1960", "29/03/2003"),
infarct1 = c(TRUE, NA, TRUE, NA, NA, TRUE),infarct2 = c(TRUE, TRUE, TRUE, TRUE, NA, TRUE, stringsAsFactors = F)
基本上我只需要保留 1 个患者 ID(又名,消除重复的 PatientID),基于最近的梗塞(最后一个 infarct==TRUE [但任何类型的梗塞] 基于 date)。
所以我想要的结果是这样的:
df <- data.frame(PatientID = c("3454","345"), date = c("29/03/2004", "05/2/2021"),
infarct = c(TRUE,TRUE), stringsAsFactors = F)
希望这是有道理的。
谢谢
【问题讨论】:
标签: r duplicates conditional-statements conditional-formatting