You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中筛选满足portal_reg_date前后1年随访的患者就诊记录

患者就诊记录筛选需求

现有5名患者的重复就诊数据,每行代表一次就诊(consdate),患者随访周期为regstartdate至end_date,目标日期为portal_reg_date。需筛选符合以下条件的记录:

  • 保留consdate在portal_reg_date前1年内的行;
  • 保留consdate在portal_reg_date后1年内的行;
  • 仅保留满足上述条件且portal_reg_date前后1年均处于regstartdate至end_date区间内的患者(patid)的记录。

数据生成代码

dfr <- tibble::tribble(
  ~patid, ~consdate, ~portal_reg_date, ~regstartdate, ~end_date,
  1, "2020-02-26", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2015-06-19", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-06-28", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2020-03-02", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-04-11", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-06-02", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-05-23", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-05-21", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-06-18", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-04-08", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-06-24", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2020-10-17", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-07-03", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2011-06-02", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-02-10", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2013-12-09", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-01-31", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-09-30", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2021-05-17", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-11-04", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2011-04-27", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-01-07", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-01-31", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-03-13", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2016-12-22", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-09-01", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-07-31", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-02-03", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-01-10", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-10-02", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-10-30", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-02-24", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2016-12-21", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-02-28", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-05-20", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-04-08", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-01-12", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-06-06", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-10-31", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-03-11", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2016-12-08", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2018-07-13", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2017-05-09", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-03-20", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-10-29", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-02-27", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2015-10-05", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2014-05-06", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-05-09", "2017-06-19", "2010-10-06", "2021-08-15",
  1, "2019-09-12", "2017-06-19", "2010-10-06", "2021-08-15"
)

筛选规则示例

  • 若consdate为2020-02-26,portal_reg_date为2017-06-19:不符合,因consdate超出portal_reg_date后1年;
  • 若consdate为2017-04-11,portal_reg_date为2017-06-19:符合,因consdate在portal_reg_date前1年内,且regstartdate(2010-10-06)与end_date(2021-08-15)覆盖该日期与portal_reg_date;
  • 若consdate为2018-06-18,portal_reg_date为2017-06-19:符合,因consdate在portal_reg_date后1年内,且regstartdate与end_date覆盖该日期与portal_reg_date。

内容的提问来源于stack exchange,提问作者abrar_r

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 07:10:12