Consider a dataset with missing values:
ds={<|"timestamp" ->
DateObject[{2000, 1, 1, 1, 0, 0}, "Instant", "Gregorian", 2.],
"BASCH" -> 108., "BONAP" -> Missing["Unrecognized", "n/d"],
"PA18" -> 65.,
"VERS" -> 47.|>, <|"timestamp" ->
DateObject[{2000, 1, 1, 2, 0, 0}, "Instant", "Gregorian", 2.],
"BASCH" -> 104., "BONAP" -> 60., "PA18" -> 77.,
"VERS" -> 42.|>, <|"timestamp" ->
DateObject[{2000, 1, 1, 3, 0, 0}, "Instant", "Gregorian", 2.],
"BASCH" -> 97., "BONAP" -> 58., "PA18" -> 73.,
"VERS" -> 34.|>, <|"timestamp" ->
DateObject[{2000, 1, 1, 4, 0, 0}, "Instant", "Gregorian", 2.],
"BASCH" -> 77., "BONAP" -> 52., "PA18" -> 57.,
"VERS" -> 29.|>, <|"timestamp" ->
DateObject[{2000, 1, 1, 5, 0, 0}, "Instant", "Gregorian", 2.],
"BASCH" -> 79., "BONAP" -> 52., "PA18" -> 64., "VERS" -> 28.|>}
I can get the mean of a given key easily, even with missing values:
no2[Mean, "BONAP"]
(*64.0017*)
But if I try to apply Mean to 2 columns, the Missing values become a problem:
no2[Mean, {"BONAP", "PA18"}]
This returns a dataset with missing values. I suspect that this is not the right syntax, since in the first case the result is numeric, while the second operation returns a dataset. How does one apply a function to several columns?
Edit:
This works:
no2[Mean, #] & /@ {"BASCH", "BONAP", "PA18", "VERS"}
But is not what I'm looking for. I'm looking for a way to do it within the framework of the dataset.
ds[Transpose, 2 ;;][All, Mean]
. But this does not work:ds[Transpose /* Map[Mean], 2 ;;]
. I am not confident enough withDataset
to answer. $\endgroup$ds[Transpose /* Query[All, Mean], 2;;]
, see my answer (at the bottom). The problem is that theMissingBehavior
is only applied to a small hard-coded list of operators, which does not includeMap[...]
$\endgroup$