Skip to main content
Commonmark migration
Source Link

##TemporalData + ResamplingMethod

TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##Association + KeyUnion

Association + KeyUnion

KeyValueMap[List]/@KeyUnion[Association/@(Rule @@@ # & /@ {a, b})]/. _Missing -> {}

{{{1, 7}, {3, 7}, {5, 2}, {8, 7}, {6, {}}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {8,7}, {6, 6}, {9, 3}}}

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##Association + KeyUnion

KeyValueMap[List]/@KeyUnion[Association/@(Rule @@@ # & /@ {a, b})]/. _Missing -> {}

{{{1, 7}, {3, 7}, {5, 2}, {8, 7}, {6, {}}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {8,7}, {6, 6}, {9, 3}}}

TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

Association + KeyUnion

KeyValueMap[List]/@KeyUnion[Association/@(Rule @@@ # & /@ {a, b})]/. _Missing -> {}

{{{1, 7}, {3, 7}, {5, 2}, {8, 7}, {6, {}}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {8,7}, {6, 6}, {9, 3}}}

added 232 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##Association + KeyUnion

KeyValueMap[List]/@KeyUnion[Association/@(Rule @@@ # & /@ {a, b})]/. _Missing -> {}

{{{1, 7}, {3, 7}, {5, 2}, {8, 7}, {6, {}}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {8,7}, {6, 6}, {9, 3}}}

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##Association + KeyUnion

KeyValueMap[List]/@KeyUnion[Association/@(Rule @@@ # & /@ {a, b})]/. _Missing -> {}

{{{1, 7}, {3, 7}, {5, 2}, {8, 7}, {6, {}}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {8,7}, {6, 6}, {9, 3}}}

added 186 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{a, b##}, ResamplingMethod -> {"Constant", {}}];], times},
  times = Union @@ td["TimeList"];
 
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ timestimes]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

td = TemporalData[{a, b}, ResamplingMethod -> {"Constant", {}}];
times = Union @@ td["TimeList"];
 
Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

##TemporalData + ResamplingMethod

ClearAll[timeAlign]
timeAlign = Module[{td = TemporalData[{##}, ResamplingMethod -> {"Constant", {}}], times},
  times = Union @@ td["TimeList"];
  Thread[{times, #}] & /@ Through @ td["PathFunctions"] @ times]&;

Example: using Mr.Wizard's example lists

a = {{1, 7}, {3, 7}, {5, 2}, {8, 7}};
b = {{3, 1}, {6, 6}, {8, 7}, {9, 3}};

timeAlign[a, b]

{{{1, 7}, {3, 7}, {5, 2}, {6, {}}, {8, 7}, {9, {}}},
{{1, {}}, {3, 1}, {5, {}}, {6, 6}, {8, 7}, {9, 3}}}

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading