hi claude.bellavance
I am also dissatisfied with the idea of "Ties are broken arbitrarily". there should at least be an option to change that to ties get same rank like would happen in a regular ordinal variable.
I have another way to "rank by" without sorting the table - in my case sorting is a nuisance. it gives equal values to the ties.
best,
ron
Names Default To Here( 1 );
// define the data source
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// add a column for the rank
dt << New Column( "Rank" , numeric, ordinal);
//// option 1: Rank by Column
// extract the list of the by variable levels
byvarlist = associative array (dt:age) << get keys;
// create seperate rank lists of height for each age group
for (ib = 1, ib<= nitems(byvarlist), ib++,
eval (parse( "heightlist"||char(byvarlist[ib])||" = Associative Array( "|| char( dt:height[dt << get rows where (:age == byvarlist[ib])])||" ) << get keys"));
);
for (ic = 1, ic<=nrows(dt), ic++,
:Rank [ic] = eval( parse ( "loc( heightlist "||char(dt:age[ic] )||" ,"||char( dt:height[ic])||" ) " ));
);
//see if it worked
dt<< Sort(
By( :age, :height ),
Order( Ascending, Ascending )
);
////
//// Option 2: Rank (without a by column)
// get the unique values for height as a list
heightlist = Associative Array( dt:height ) << get keys;
For( i = 1, i <= N Rows( dt ), i++,
dt:Rank[i] = Loc( heightlist, :height[i] );
);
//see if it worked
dt<< Sort(
By( :height ),
Order( Ascending )
);