Expressions to Select Rows

Prev Next

Introduction

Expressions to select rows are a variant of code pieces containing expressions, but provide additional flexibility. These expressions are typically used in functions with names containing ... selected rows ... where expressions are applied to chosses specifc rows to include in the data processing.

Like expressions specified as code pieces, these expressions can be coded directly or provided as strings with preceding colon (:) symbols.

The expressions may return values of following types:

boolean If it is an expression returning boolean values, then this expression will be calculated for every row, starting with row 1 (excluding the header row). Typically, processing will be done on the corresponding rows if the outcome is true.
numeral If the expression returns a numeral, then one single row number is meant. Negative indexing is allowed, e.g. -1 refers to the last row.
parameter set If the expression returns a parameter set, the the row numbers inside the parameter sets will be used. Negative indexing is allowed. The parameter set must contain numerals (row numbers) or may be an empty set if no rows shall be selected. Negative indexing is allowed, i.e. -1 refers to the last row.
Note: Even if row numbers are specified in different orders or multiple times, the table will be processed from top to bottom, and every matching row will processed only once.

  table initialize ( table,
  { { Animal, leg count }, { Worm,  0}, { Bird, 2 }, { Dog, 4 }, { Fly, 6 }, { Tick, 8 } } );

  table process selected rows(
      table, ([Animal]=Tick,Bird),
      echo( "row nr.: ", row(),"  Animal: ", [Animal], " has ", [leg count], " legs" ) );

  echo;
  table process selected rows(
      table, -1, // -1 -> Row 5 (Negative indexing)
      echo( "row nr.: ", row(),"  Animal: ", [Animal], " has ", [leg count], " legs" ) );

  echo;
  table process selected rows(
      table, {1,3,-2},  // -2 -> Row 4 (Negative indexing)
      echo( "row nr.: ", row(),"  Animal: ", [Animal], " has ", [leg count], " legs" ) );
row nr.: 2  Animal: Bird has 2 legs
row nr.: 5  Animal: Tick has 8 legs

row nr.: 5  Animal: Tick has 8 legs

row nr.: 1  Animal: Worm has 0 legs
row nr.: 3  Animal: Dog has 4 legs
row nr.: 4  Animal: Fly has 6 legs
Try it yourself: Open LAN_Features_Expression_to_select_rows.b4p in B4P_Examples.zip. Decompress before use.