该帮助的版本不再更新,请参见https://www.jmp.com/support/help/zh-cn/15.2 获取最新的版本.


A key can exist only once in an associative array, so putting a column’s values into one automatically results in the unique values. For example, the Big Class.jmp sample data table contains 40 rows. To see how many unique values are in the column height, run this script:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
unique heights = Associative Array( dt:height );
There are only 17 unique values for height. You can use those unique values by getting the keys:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dtbig = New Table( "Really Big Class",
New Column( "name",
Set Values( nms[J( 100000, 1, Random Integer( N Items( nms ) ) )] )
Wait( 0 );
t1 = Tick Seconds();
"\!N# names from Really Big Class = ",
N Items( Associative Array( dtbig:name ) ),
", elapsed time=",
Tick Seconds() - t1
Because keys are ordered lexicographically, putting the values into an associative array also sorts them. For example, the <<Get Keys message returns the keys (unique values of the names column) in ascending order:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
unique names = Associative Array( dt:name );
dt1 = Open( "$SAMPLE_DATA/BirthDeathYear.jmp" );
dt2 = Open( "$SAMPLE_DATA/World Demographics.jmp" );
aa1 = Associative Array( dt1:Country );
aa2 = Associative Array( dt2:Territory );
Use N Items() to see how many countries appear in each data table:
N Items(aa1);
N Items(aa2);
Use the <<Intersect message to find the common values:
aa1 = Associative Array( dt1:Country );
aa1 << Intersect( aa2 );
Show(N Items(aa1), aa1 << Get Keys);