I have a Dataset[]
with some data and a TON of columns. Each row contains several columns for dates, which contain DateObject
values, but they aren't always populated. If a value is Null, I've replaced it with Missing[]
for a) prettier display in Dataset visualization, b) to allow use of MissingQ
and DeleteMissing
.
Here's my question. I am trying to get a single definitive date for each row based on the first non-Missing value. It's possible that ALL values will be missing. In that case either nothing needs to be returned or a Missing["No date"]
is fine.
What I have so far is very ugly and crude, and I'm wondering if there's a more elegant way to do this, that simply escapes me for now?
Flatten[
Take[ DeleteMissing@#, UpTo[1] ]& /@
Normal@Values@encounters[ All,
{"ArriveDTS", "EstimatedArriveDTS", "RegistrationDTS",
"TriageDTS", "InpatientAdmitDTS", "AssignToLocationDTS",
"DischargeDTS", "DepartDTS", "EstimatedDepartDTS",
"PreRegistrationDTS"}
]
]
SelectFirst[Not @* MissingQ]
? $\endgroup$encounters[All, SelectFirst[Not@*MissingQ]@*KeyTake[{"ArriveDTS", "EstimatedArriveDTS", "RegistrationDTS", "TriageDTS", "InpatientAdmitDTS", "AssignToLocationDTS", "DischargeDTS", "DepartDTS", "EstimatedDepartDTS", "PreRegistrationDTS"}]]
$\endgroup$