Seeking TimeSeries advice for simulating Dataset subsets using named columns (e.g., timeseries[[All, {"SBP", "DSP", "HR"}]].


While writing biometric data pipeline processors in Mathematica, I typically use TimeSeries whose ValueDimensions are 2 or more. But the downside is that I'm having to load the TimeSeries MetaInformation with property lists to retain information such as which position in the list is associated with a variable name, its units of measurement, etc .... and then I'm writing custom functions to fetch slices of the TimeSeries data.

My immediate goal is to simulate Dataset extraction syntax for subsets. For example, timeseries[[All, {"SBP", "DSP", "HR"}]] will return a TimeSeries slice of all {timestamp, Systolic Blood Pressure, Diastolic Blood Pressure, Heart Rate} measurements.

Whereas if I always put the biometric data into a Dataset, I get all those data slicing features for free, but then when I need to do specific TimeSeries processing, I'm having to call Normal, Value and the like to extract slices of the data from the Dataset into a temporary TimeSeries structure.

Is there a published Mathematica package that enhances TimeSeries with Dataset like features?

  • 4
    $\begingroup$ If you include a toy data set and show what you are currently doing with either TimeSeries or Dataset on it, it would be a lot easier to help. Otherwise we would have to come up with fake data to play around with, and perhaps our solution would still not work for you because we do not know the exact format of your data. $\endgroup$
    – MarcoB
    Apr 9, 2021 at 19:01
  • 2
    $\begingroup$ Would "ComponentNames" help? e.g. ts = TimeSeries[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, Automatic, MetaInformation -> {"ComponentNames" -> {"SBP", "DSP", "HR"}}] and then ts["PathComponent", {"SBP", "DSP"}]. $\endgroup$
    – WReach
    Apr 10, 2021 at 4:16
  • $\begingroup$ WReach -- thank you! Using "ComponentNames" and "PathComponent" definitely gets me closer to my end-goals. Next step: when I generate a DateListPlot, I want to identify which ComponentName is displayed in the plot using that MetaInformation. Along the line of Association's "Keys", is there a better, more elegant strategy than the following? --- keys[ts_TemporalData] := keys[ts] = Flatten [ "ComponentNames" /. ts["MetaInformation"]]; $\endgroup$ Apr 11, 2021 at 15:11

1 Answer 1


We can use the MetaInformation option to TimeSeries to name each of the path components. For example:

ts =
    { RandomInteger[{110, 130}, 10]
    , RandomInteger[{70, 90}, 10]
    , RandomInteger[{60, 100}, 10]
    } // Transpose
  , Automatic
  , MetaInformation -> {"ComponentNames" -> {"SBP", "DSP", "HR"}}


We can create another time series which contains only a subset of the paths from the first.

ts2 = ts["PathComponent", {"SBP", "DSP"}]


The subset can be plotted, complete with a plot legend containing the component names:

DateListPlot[ts2, PlotLegends -> ts2["ComponentNames"]]


The valid properties of a series can be found thus:


(* { "ComponentNames", "DatePath", "Dates", "FirstDate",
     "FirstTime", "FirstValue", "LastDate", "LastTime",
     "LastValue", "Path", "PathComponent", "PathComponents",
     "PathFunction", "PathLength", "Times", "ValueDimensions",
     "Values" } *)

See the TimeSeries documentation for details of each.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.