F - Analyze

Prev Next

Overview

Time to do the real world after all data inputs available in the quality needed. Use the full B4P capabilities and function libraries such as statistics functions to analyze the data and draw meaningful conclusions. The functions listed below could be of interest, but check the function library first before implementing something wtih low level code such as individual calculations.

  • table process selected rows() to apply algorithms of choice on rows selected with an expression.
  • Do a pivot by combining table spread() to spread values horizontally and then do table consolidate() eliminate unnecessary rows.
  • Do a pivot by moving horizontal data to vertical data with table serialize().
  • table distribute() becomes very handy for production planning: Knowing the number of units ordered, lot sizes, delivery start and end dates, and some cultural information like bank and school holidays (vacations), you generate the production plan with one function call.



Wikipedia Example (continued from step 5)

Do some validation on this table:

  • Load a list of languages by countries from Wikipedia
  • Align country names in the country table, e.g. 'Viet Nam' to 'Vietnam'.
  • Merge the language data into the country data.

Simple Example
  languages in focus[]           = { Chinese, English, French, Spanish, German, Russian, Hindi };
  table keep selected rows       ( countries, (tokenize( [Languages], {}, {' ',','} ) & languages in focus[]) != {} );

  table insert columns           ( countries, languages in focus[] );
        table process cells in columns ( countries, languages in focus[], if ([Languages] = '*'+soft([.,0])+'*') [.]=1; );

  table list( countries, briefly, 8 ); // List first and last 8 rows only

  table delete columns           ( countries, {'Alpha-2 code', Languages} );

  table copy table               ( countries, summary );
  table keep columns             ( summary, languages in focus[] );
        table consolidate              ( summary, {}, languages in focus[], sum );
  table transpose                ( summary );
  table insert rows              ( summary, 0 );
  [ summary: ..,0]               = { Language, '# Countries' };
  table sort rows                ( summary, '# Countries', numeric down);

  echo ("Brief summary on key languages:");
  table list ( summary );
Processing completed.
Row #: Code Text _______________________________________________________
    1:   include ( Support Library );
    2:   table load                     ( countries, temp.csv); // Hide!  Step 6 begins
    3:   languages in focus[]           = { Chinese, English, French, Spanish, German, Russian, Hindi };
    4:   table keep selected rows       ( countries, (tokenize( [Languages], {}, {' ',','} ) & languages in focus[]) != {} );
                                                                          ^
Inside an expression supplied as a parameter to function 'table keep selected rows':
Attempting to access table with column name [Languages].
Specified table column name or number is invalid.
Code execution will stop.  Going to interactive mode
-------------------------------------------------------------------------------
Type 'help' for help, 'docs' or 'toc' for online B4P documentation.
>>
Try it yourself: Open GUI_Features_Align_and_Process.b4p in B4P_Examples.zip. Decompress before use.