MathGroup Archive 2008

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

Search the Archive

Intersection of lists of lists based on the first term

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87485] Intersection of lists of lists based on the first term
  • From: Stern <nycstern at gmail.com>
  • Date: Fri, 11 Apr 2008 01:47:51 -0400 (EDT)

There is something I've been doing inefficiently that I think might be done
much better, and was hoping folks here could help.

I am working with time series data in the form
seriesA={{timestamp1A,data1A},{timestamp2A,data2A}....{timestampNA,dataNA}};
seriesB={{timestamp1B,data1A},{timestamp2B,data2B}....{timestampNB,dataNB}};
etc.
where the many of the timestamps will be in common between the series, but
not all.

I frequently need to work with only those data which are available in all
the time series, and I have written a function that does this, in the
simplest case, by first working out the timestamps that all the series share
in common

timestampsincommon=Intersection @@ Map[Transpose[#][[1]] &,
{seriesA,seriesB....seriesN}];

then running Select based on MemberQ

Map[Select[#, MemberQ[timestampsincommon, #[[1]]] &] &,
{seriesA,seriesB....seriesN}];

This works, but the completion time increases roughly linearly with the
number of datapoints involved, and is slow when the number of points gets
large, and it seems inelegant. I was hoping somebody on the list might
suggest a better way.

Thank you,

Michael



  • Prev by Date: Re: A Problem with Simplify
  • Next by Date: Re: Path, Get, etc.
  • Previous by thread: Re: ContourPlot, etc.: not every point a Real
  • Next by thread: Re: Intersection of lists of lists based on the first term