MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

grouping similar list elements with gaps

  • To: mathgroup at
  • Subject: [mg73468] grouping similar list elements with gaps
  • From: Stern <nycstern at>
  • Date: Sun, 18 Feb 2007 06:13:31 -0500 (EST)

I work with time series data of the form
{{timecode1,datum1},{timecode2,datum2},...}. The timecodes can be in
any of several formats, but for internal calculations I convert them
to "Mathematica integer" format, which is to say, the absolute number
of seconds since the beginning of January 1, 1900.

My current interest involves continuous runs of dates above or below a
defined threshold. This is relatively easy, using the Split and Select
commands. For example,

Select[Split[TIMESERIESLIST, Sign[#1[[2]] - THRESHOLD] ==
    Sign[#2[[2]] - THRESHOLD] &], (Min[Transpose[#][[2]]] ? THRESHOLD) &]

(Thanks to Bob Hanlon, for suggesting this basic approach).

I would like to generalize this to handle cases where there are small
gaps in the pattern. So, for example, if I am willing to tolerate a
gap of 3, then if list members 3-100 are above the threshold and list
members 102-200 are above the threshold, then the entire period 3-200
is marked as above, though time unit 101 would, on its own, fail.

This may need to be handled recursively, as combined periods above the
threshold may fall close enough together that they should be combined
in turn.

I have thought of some relatively inelegant ways of handling this
("preprocessing" the time series to create a dummy list in which gaps
have been adjusted over the threshold), but I feel as though there
ought to be a better way to handle it.

Thanks in advance for any help,


  • Prev by Date: Re: How to apply a function to a function multiple times
  • Next by Date: Re: cellform to console form
  • Previous by thread: Re: explanation need!
  • Next by thread: Re: grouping similar list elements with gaps