Let’s imagine a clinic keeping track of their patients’ DoB and first visits.
Birth |
Visit |
1959-11-22 |
2021-06-12 |
1961-01-07 |
2021-06-25 |
1992-06-19 |
2018-12-26 |
In DataSHIELD, we would like to pool ages of diagnoses, based on dates of birth and visit, like so:
Birth |
Visit |
Age of Diagnosis |
1959-11-22 |
2021-06-12 |
61 |
1961-01-07 |
2021-06-25 |
60 |
1992-06-19 |
2018-12-26 |
26 |
I am fairly certain this should be possible through assignment operations but I was not able to find how to do this. Do I have no choice but to compute AoD locally, before creating the table on DataSHIELD?
Thanks in advance!
Hi Ahmet,
The dsSwissKnifeClient package has some functions to deal will dates (see for example dssAddDaysInterval). However, i have never use this package so i can’t give any further information.
Demetris
1 Like
Hi Ahmet,
ISGlobal has produced a package called dsDates (GitHub: isglobal-brge/dsDates), but I don’t know if it is still supported.
Stuart
1 Like
dssAddDaysInterval in conjunction with dssDeriveColumn did the trick!
library(dsSwissKnifeClient)
# Compute Age in Days
dsSwissKnifeClient::dssAddDaysInterval(
newobj='D_',
df='D',
description.list= list(
'age_in_days' = list( end_date='Visit',start_date ='Birth')
),
datasources= conns)
# Compute Age in Years
dsSwissKnifeClient::dssDeriveColumn('D_', 'age_in_years', 'age_in_days/365', datasources = conns)