From 65856943c2579247a4742d127046aa3822748463 Mon Sep 17 00:00:00 2001 From: Pranav Anbarasu Date: Wed, 20 Mar 2024 17:23:00 +0000 Subject: [PATCH] Assign earliest non-device concept startdate to device concept startdate for each participant --- scripts/write-output/final-output-concepts.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/write-output/final-output-concepts.R b/scripts/write-output/final-output-concepts.R index 9af8e24..b97c852 100644 --- a/scripts/write-output/final-output-concepts.R +++ b/scripts/write-output/final-output-concepts.R @@ -44,7 +44,10 @@ valid_participants <- combined_output_concepts <- combined_output_concepts %>% - filter(participantidentifier %in% valid_participants) + filter(participantidentifier %in% valid_participants) %>% + group_by(participantidentifier) %>% + mutate(startdate = ifelse(concept=="mhp:device", min(startdate[concept != "mhp:device"], na.rm = TRUE), startdate)) %>% + ungroup() combined_output_concepts %>% write.csv(file.path(outputConceptsDir, "output_concepts.csv"), row.names = F)