6
$\begingroup$

I want to get the time in a time series that a particular event (e.g., the minimum value) occurs. The approach I take below seems clumsy. Is there a better way?

ts = TimeSeries[FinancialData["GE", "Jan. 1, 2007"]];
DateListPlot[ts]

enter image description here

6.66 = Min[ts]
p = Position[ts["Values"], Min[ts]][[1, 1]];
ts["DatePath"][[p]]

{DateObject[{2009, 3, 5, 0, 0, 0.}], 6.66}
$\endgroup$
6
$\begingroup$

A few other versions, the first one being the cleanest in a sense that it combines operation of finding the minimum and extracting the date.

MinimalBy[Normal[ts], Last]

Cases[Normal[ts], {_, Min[ts]}]

Cases[ts["DatePath"], {_, Min[ts]}]

Extract[Normal[ts], Position[ts["Values"], Min[ts]]]
$\endgroup$
  • $\begingroup$ Thanks, Vitaliy. I appreciate the different examples. I didn't know about Extract. $\endgroup$ – George Wolfe Nov 12 '17 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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