Lists and COLLECT()


Tutorial Index     Rules & Decision Tables     Column Queries     Arrays     Tables & Pattern Matching     Lists     VBA     Multiple Rule Sets     Array Queries


loans_06_lists.xls

Rather than adding columns to the worksheet input data, the application might require separate reporting of all the loans a particular investor can accept. For Ace, this would be loans 101, 104, 105, 108, 110 and 112.

Lists are represented in ARulesXL with square brackets, so the resaleable loans for Ace would be: [101, 104, 105, 108, 110, 112].

Lists are generated in ARulesXL using the COLLECT statement. Here is our application requirement:

For a given investor, find all the loan ids of loans that can be resold to that investor.

And here is how it is expressed in ARulesXL using COLLECT to loop through all the loans looking for the resaleable ones:

Resaleable[ ?investor ] = COLLECT ?id FOREACH ?id = INDEX( loans, 1 ) WHERE Resell[?investor, ?id] = yes

For Resaleable['Ace'], this will create the list [101, 104, 105, 108, 110, 112] as shown in the screen shot. COLLECT and the INDEX() function are explained in more detail below.


loans_06_lists.xls

The syntax of COLLECT is:

COLLECT item(s) FOREACH loop variable(s) WHERE condition(s)

COLLECT can also be entered as a function with three arguments:

COLLECT( item(s), loop variable(s), condition(s) )

This is useful when other ARulesXL list processing functions are to be applied to the list. For example, the SORT() function might used to sort the list output from COLLECT().

The values of the loop variables can be set in a variety of ways. In this case the values are the row indices of the input table loans. The INDEX() function can be used to generate all of the index values from a table. The syntax is:

INDEX( table, index )

So in the example INDEX( loans, 1 ) will generate the values 101, 102, 103, ..., 115. If column indices were needed, INDEX( loans, 2 ) would generate the values AMOUNT, FICO, LTV, Occupancy, and Rate.

 


Copyright ©2005-7 Amzi! inc. All Rights Reserved.
ARulesXL and Amzi! are trademarks or registered trademarks of Amzi!
Microsoft and Excel are trademarks or registered trademarks of Microsoft Corporation.