3
$\begingroup$

I'm working with some data which includes an extensive list of dates. Some dates will appear multiple times, with each individual entry representing the date on which an event occurred. I would like to create a Time Series and Date List Plot, plotting the number of events against the date.

Eg. The data is as follows:

{"03/12/2022", "03/12/2022", "03/12/2022", "03/03/2022", "03/12/2022", "03/12/2022", "03/03/2022", "03/12/2022", "03/12/2022"}

As you can see, "03/12/2022" appears 7 times, so I'd like the value to be 7 on this date in the Time Series, and so on.

How can this be best achieved?

$\endgroup$
2
  • 1
    $\begingroup$ try DateHistogram[ DateString[{#, {"Month", "/", "Day", "/", "Year"}}] & /@ yourlist, "Day"]? $\endgroup$
    – kglr
    Mar 25 at 17:10
  • $\begingroup$ Are your date strings normal or USA format? $\endgroup$
    – Edmund
    Mar 25 at 17:53

1 Answer 1

1
$\begingroup$

Assuming the data are similar to the list presented in the question, it could be as simple as

process = Tally/*Transpose/*Reverse/*Apply[TemporalData[#1,{#2}]&]

Assuming events is a symbol that stores a list of event dates, similar to the one presented in the question, then

events // process

would evaluate to a TemporalData object.

Alternatively, it is possible to substitute EventSeries for TemporalData if the underlying data represent discrete events.

For more information check the official documentation for TemporalData.

$\endgroup$
2
  • $\begingroup$ Thanks Yosimitsu, this seems to work perfectly. It was specifically TimeSeries I was looking to use, so I substituted this for TemporalData in your suggested process. It ran very quickly for a large dataset; far faster than I anticipated. Thanks again. $\endgroup$
    – sro
    Mar 26 at 10:29
  • $\begingroup$ @sro it's nice to know it worked for you; just for completeness sake, allow me to point out that a TimeSeries is special case of a TemporalData object; try using FullForm on two instances of them and notice the result; having said that, the code can easily be adapted to suit your needs, as you've already noted; take care! $\endgroup$ Mar 26 at 18:07

Your Answer

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

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