Page 1 of 1

including or excluding countries

PostPosted: 29 Oct 2013, 21:00
by lotus85
Hi,
how can i obtain a subtable of a big data table by including or excluding certain countries? country is one of the many fields of table.

Filtering rows of table with a condition table

PostPosted: 30 Oct 2013, 21:19
by finaquant
You can use Table Function (*) MatrixTable.FilterTableA() for filtering tables.

(*) Table Functions in our .net libraries finaquant® protos (non-commercial) or finaquant® calcs (commercial).

See the example code below that you can find in the demo function named Filtering_tables_with_conditions ion Visual Studio file FinaquantProtosStarter or FinaquantCalcsStarter that you can download at their respective product page (links above).

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // ****************************************************************
  2. // Filtering rows with a condition table
  3. // ****************************************************************
  4.  
  5. // initiate variables
  6. MatrixTable FilteredTable;
  7.  
  8. // create condition table
  9. TableFields CondTableFields = TableFields.CreateEmptyTableFields(md);
  10. TableFields.AddNewField(CondTableFields, "family");
  11. TableFields.AddNewField(CondTableFields, "birth_year");
  12.  
  13. MatrixTable CondTable = MatrixTable.CreateTableWithElements_A(CondTableFields,
  14.     "mammals", 0,       // all years              
  15.     "ALL", 2005,        // all families          
  16.     "Fish", 2008
  17.     );
  18.  
  19. // view table
  20. MatrixTable.View_MatrixTable(CondTable, "Filtering with condition table: Condition table");
  21.  
  22. // CASE 1: Include (select) mathched rows: ExcludeMatchedRows = false
  23. FilteredTable = MatrixTable.FilterTableA(AnimalsTable, CondTable,
  24.     ExcludeMatchedRows: false, JokerMatchesAllvalues: true, TextJoker: "ALL", NumJoker: 0);
  25.  
  26. // view resultant filtered table
  27. MatrixTable.View_MatrixTable(FilteredTable, "Filtering with condition table (include): Output table");
  28.  
  29. // CASE 2: Exclude (deselect) mathched rows: ExcludeMatchedRows = true
  30. FilteredTable = MatrixTable.FilterTableA(AnimalsTable, CondTable,
  31.     ExcludeMatchedRows: true, JokerMatchesAllvalues: true, TextJoker: "ALL", NumJoker: 0);
  32.  
  33. // view resultant filtered table
  34. MatrixTable.View_MatrixTable(FilteredTable, "Filtering with condition table (exclude): Output table");
GeSHi ©


Image

CASE1 above is for inclusion, CASE2 is for exclusion of attribute values.

In your case, if you want to exclude the countries Peru and Bolivia, your code would look like as follows:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. MatrixTable CondTable = MatrixTable.CreateTableWithElements_A(CondTableFields,
  2.     "Peru",
  3.     "Bolivia"
  4.     );
  5. FilteredTable = MatrixTable.FilterTableA(BigTable, CondTable, ExcludeMatchedRows: true);
GeSHi ©

Re: including or excluding countries

PostPosted: 01 Nov 2013, 20:21
by lotus85
perfect, thanks.