How to split a table into multiple smaller tables?

Table-valued functions in finaquant .net libraries

How to split a table into multiple smaller tables?

Postby kubot » 26 Jul 2014, 12:17

we use finaquant's protos in a calculation engine for ecological population forecasts. We have a big table with multiple regions, including many attributes other than region. How can we split this table into smaller tables each containing data for a single region? Is there a ready-to-use table function for this purpose or do we need to write some code?
Thanks, Martin
Posts: 2
Joined: 26 Jul 2014, 12:11

Re: How to split a table into multiple smaller tables?

Postby finaquant » 05 Aug 2014, 17:44

Yes, there is a table function (a method of MatrixTable class) to split a table into smaller subtables:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. /// <summary>
  2. /// Generate sub-tables with selected columns (SubColumns) that correspond to rows of unique attribute table (UniqueAttributeTbl).
  3. /// </summary>
  4. /// <param name="Tbl">Input table</param>
  5. /// <param name="SubColumns">Fields of subtables; each subtable corresponds to a row of unique attribute table</param>
  6. /// <param name="UniqueAttributeTbl">Unique table with attribute fields that are not in SubColumns</param>
  7. /// <param name="SubTables">SubTables[n] corresponds to n'th row of table UniqueAttributeTbl; a subtable for each row of unique table</param>
  8. /// <remarks>
  9. /// - error if vector SubColumns is empty
  10. /// - error if input table Tbl is empty
  11. /// - error if SubColumns is not a unique vector
  12. /// - error if not all fields in SubColumns are found in input table
  13. /// </remarks>
  14. public static void GetSubTables(MatrixTable Tbl, TextVector SubColumns,
  15.     out MatrixTable UniqueAttributeTbl, out MatrixTable[] SubTables)
GeSHi ©

You can also use high-level table functions like Subtable Transformer or Function Router in order to apply table or matrix functions on selected subtables of a table.

A subtable transformer applies the same table (or matrix) function on each subtable of an input table.

A function router applies selected table (or matrix) functions on selected subtables of an input table.
User avatar
Posts: 61
Joined: 16 Sep 2013, 18:37

Return to Table Functions

Who is online

Users browsing this forum: No registered users and 1 guest