including or excluding countries

Table-valued functions in finaquant .net libraries

including or excluding countries

Postby lotus85 » 29 Oct 2013, 21:00

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.
lotus85
 
Posts: 6
Joined: 24 Sep 2013, 19:59

Filtering rows of table with a condition table

Postby finaquant » 30 Oct 2013, 21:19

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 ©
User avatar
finaquant
 
Posts: 61
Joined: 16 Sep 2013, 18:37

Re: including or excluding countries

Postby lotus85 » 01 Nov 2013, 20:21

perfect, thanks.
lotus85
 
Posts: 6
Joined: 24 Sep 2013, 19:59


Return to Table Functions

Who is online

Users browsing this forum: No registered users and 1 guest

cron