0

私はこのようないくつかのデータを持っています

structure(list(id = c(1, 1, 2, 3, 4, 4, 5), deathdate = c("2007/04/10", 
"2007/04/10", "2004/04/01", "NA", "NA", "2018/01/01", "2016/01/02"
), admidate = c("2007/03/08", "2007/04/11", "2004/04/15", "2012/10/20", 
"2017/10/14", "2018/01/02", "2015/12/20")), class = "data.frame", row.names = c(NA, 
-7L))

そして、死亡日がadmidateよりも前の行を、このような新しいdfから削除したい

structure(list(id2 = c(1, 3, 4, 5), deathdate2 = c("2007/04/10", 
"NA", "NA", "2016/01/02"), admidate2 = c("2007/03/08", "2012/10/20", 
"2017/10/14", "2015/12/20")), class = "data.frame", row.names = c(NA, 
-4L))

私はこれを試しました

    deathbefore <- with(df,(!is.na(deathdate))& !is.na(admidate)& deathdate < admidate)

df2 <- df[-deathbefore,]

ただし、問題は解決しません。

4

2 に答える 2