FACSORT procedure

Sorts the levels of a factor according to an index vector (R.W. Payne).


Options

DIRECTION = string
Direction in which to sort the index (ascending, descending); default asce

SETATTRIBUTES = strings
Which aspects of each NEWFACTOR to define (levels, labels, values); default * i.e. labels and values if defined for FACTOR, also levels if not the integers 1,2...


Parameters

FACTOR = factors
Factors whose levels are to be reordered

INDEX = variate, text or one-way table
Index vectors defining the ordering of the levels of each factor

NEWFACTOR = factors
New factors with reordered levels; if unset, the original FACTOR is redefined

NEWLEVELS = variates
Saves the (reordered) levels as defined for each NEWFACTOR


Description

This procedure reorders the levels of a factor. The factor is specified by the FACTOR parameter. The NEWFACTOR parameter can specify the identifier for the new reordered factor (so that FACTOR is left unchanged). If this is not supplied, the original FACTOR is redefined with its levels in the new order.

   The order is defined by an index vector, specified by the INDEX parameter. This can be a variate, or a text, or a one-way table, whose number of values is equal to the number of levels of the factor. The levels are thus sorted in parallel with the INDEX (using the SORT directive), and the DIRECTION option indicates whether this is to be into ascending or descending order.

   The SETATTRIBUTES option specifies which of the labels, levels and values to define for the NEWFACTOR. If SETATTRIBUTES is not set, the default is to define whichever of these has been defined for the FACTOR. In particular, note that levels are then not defined if the FACTOR levels are simply 1,2...

   The NEWLEVELS parameter can specify a variate to save the levels of the NEWFACTOR. You can use this as the setting of the OLDPOSITIONS and NEWPOSITIONS parameters of the the COMBINE directive in order to reorder tables classified by the factor. Or, you can discover the (ordinal) number of the original level corresponding to each new level by

GETATTRIBUTE [ATTRIBUTE=levels] FACTOR; SAVE=FacLev

CALCULATE OldLevelNumber\

          = POSITION(NEWLEVELS; FacLev['levels'])

 

Options: DIRECTION, SETATTRIBUTES.

Parameters: FACTOR, INDEX, NEWFACTOR, NEWLEVELS.


Method

FACSORT uses the standard GenStat manipulation commands, such as SORT.


Action with RESTRICT

Any restrictions are ignored.