GDPR Cookie Consent by Free Privacy Policy Generator
post thumb
Asset Control
by Matthias Hanitzsch-Moonlight/ on 28 Mar 2019

Flip data on its side with transpose()

Sometimes it is more straightforward to traverse a data structure if you would transpose it first, i.e. instead of working on an m by n matrix you would work on the corresponding n by m matrix instead.

Let’s look at a common use case in AC: timeseries data.

By default the function ts() will return timeseries as shown here:

Timeseries returned by ts() call

You will notice that the first row contains all the dates, the second all the times and then the third contains all the prices.

If you wanted to loop over all timeseries records in a for-loop or apply a function to each record using map, you would want to use the function transpose first:

Timeseries transposed

Now each row contains a record: date, time and price together. And this might be easier to process. Or in many cases, at least easier to reason about.

comments powered by Disqus