Message Boards Message Boards

0
|
7722 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to pair two Timeseries?

Posted 8 years ago

Hello

I Have 2 tables with the folloing structure:

enter image description here

To calculate things like correlation, I want to create an new paired table like this:

enter image description here

I tried diffrent things, for example:

Timing[
 d = Intersection[smi[[;; , 1]], abb[[;; , 1]]];
 p1 = Flatten[Position[Map[MemberQ[d, #] &, smi[[;; , 1]]], True]];
 p2 = Flatten[Position[Map[MemberQ[d, #] &, abb[[;; , 1]]], True]];
 paired = Transpose[{d, smi[[p1, 2]], abb[[p2, 2]]}];
 ]

The Problem is, that this is really slow (4 seconds for about 6000 dates). I think there must be a simple and much faster solution than mine. I would be happy for a little help!

POSTED BY: Juerg Baertsch
3 Replies
Posted 8 years ago

Juerg,

A couple of suggestions... If your goal is specifically just correlation information, Mathematica has some built in functions for this. Check out the documentation for Correlation and CorrelationTest for starters.

If you're really interested in manipulating the data structures, then there are many approaches, but I don't know which ones would be most performant without benchmarking each one. The first approach that comes to my mind would be to use Associations. Check out the documentation for Association, KeyIntersection, and Merge.

POSTED BY: Eric Rimbey
Posted 8 years ago

Hi Eric

Thanks a lot for the hint. With Assosiation and KeyIntersection I get the wished result in 0.03 Seconds, so that I can work with this now!

Kind regards!

POSTED BY: Juerg Baertsch
Posted 8 years ago

Excellent!

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract