Appends a list of vectors of the compatible types (R.W. Payne).
Options
NEWVECTOR = variate, factor or text |
Vector to store the appended values; by default uses the first vector of the OLDVECTOR list |
---|---|
FREPRESENTATION = string token |
How to match the values of old factors (levels , labels , ordinals , renumbered ); default leve |
GROUPS = factor |
Factor to represent the OLDVECTOR to which each unit originally belonged |
Parameter
OLDVECTOR = variates, factors, texts or scalars |
Values to be appended |
---|
Description
APPEND
provides a convenient way of taking the values from several variates, factors, scalars, or texts and appending (i.e. copying) them into a single variate, factor or text.
The variates, factors, scalars, and texts whose values are to be appended are specified by the OLDVECTOR
parameter, and the NEWVECTOR
option supplies the variate, factor or text to store the appended values. If NEWVECTOR
is omitted, the values are placed into the first OLDVECTOR
(but it must not be a scalar). Also, the type of the NEWVECTOR
is taken from the first OLDVECTOR
, if it has not already been defined.
The NEWVECTOR
will contain all the values of the first OLDVECTOR
, then all those from the second, and so on. The old vectors can thus contain different numbers of values, but they must be of compatible types. Texts can receive values from any type of OLDVECTOR
, with the values of variates, factors scalars first being formed into texts using the TXCONSTRUCT
directive. However, variates cannot receive values from texts.
Factors can receive values from any type, subject to the setting of the FREPRESENTATION
option, described below. Variates, texts and scalars are first formed into factors, using the GROUPS
directive, and the values are then transferred into the new factor. A factor formed from a text will therefore have both levels and labels, but those formed from variates or scalars will have only levels.
The FREPRESENTATION
option indicates how the levels of factors are matched amongst the old factors. If this is set to labels
and the levels of the old factors are compatible (that is if each label corresponds to the same level in all the old factors), then the level definitions are transferred to the new factor; if not, the levels are defined to be the default values 1, 2… and a warning is printed. Similarly, with the default setting FREPRESENTATION=levels
, the labels are retained if they are compatible, but no warning is printed if they are not. For FREPRESENTATION=ordinals
, the levels of all the factors are taken as the ordinal values 1, 2… (and no labels are defined). Finally, the renumbered
setting assumes that the old factors all have independent sets of levels, and renumbers these from one upwards for the first factor, from number of levels of the first factor plus one upwards for the second factor, and so on; the new factor will thus have a different level for every level of the original factors.
The GROUPS
option allows a factor to be formed indicating the OLDVECTOR
to which each unit of the appended vector originally belonged. The levels are labelled by the identifier of the corresponding OLDVECTOR
. This factor could be used in the CONDITION
option of the SUBSET
procedure subsequently to recover the values of the original vectors.
Options: NEWVECTOR
, FREPRESENTATION
, GROUPS
.
Parameter: OLDVECTOR
.
Method
APPEND
defines the lengths and all other relevant attributes of the NEWVECTOR
and then uses EQUATE
to transfer the values.
Action with RESTRICT
See also
Directive: EQUATE
.
Procedures: STACK
, VEQUATE
.
Commands for: Calculations and manipulation.
Example
CAPTION 'APPEND examples'; STYLE=meta APPEND [NEWVECTOR=Newvar] !(1...3),!(11...12),!(21) APPEND [NEWVECTOR=Newtext] !t(a,b,c),!t(d,e),!t(f) PRINT Newvar,Newtext FACTOR [LEVELS=3; VALUES=3,2,1] F1 FACTOR [LEVELS=!(11,12); VALUES=12,11] F2 FACTOR [LEVELS=!(21...23); VALUES=21] F3 " old factors only have levels: match by levels " APPEND [NEWVECTOR=Newfac1; GROUPS=Oldvec] F1,F2,F3 " old factors only have levels: match by ordinals " APPEND [NEWVECTOR=Newfac2; FREPRESENTATION=ordinals] F1,F2,F3 " old factors only have levels: renumber " APPEND [NEWVECTOR=Newfac3; FREPRESENTATION=renumbered] F1,F2,F3 PRINT Oldvec,Newfac1,Newfac2,Newfac3 FACTOR [LEVELS=3; LABELS=!t(a,b,c); VALUES=3,2,1] F1 FACTOR [LEVELS=!(11,12); LABELS=!t(d,e); VALUES=12,11] F2 FACTOR [LEVELS=!(21...23); LABELS=!t(f,g,h); VALUES=21] F3 " old factors only have labels and compatible levels: matching by levels " APPEND [NEWVECTOR=Newfac1] F1,F2,F3 " old factors only have labels and compatible levels: matching by labels " APPEND [NEWVECTOR=Newfac2; FREPRESENTATION=labels] F1,F2,F3 PRINT 2(Newfac1,Newfac2); FREPRESENTATION=labels,levels FACTOR [LEVELS=3; LABELS=!t(a,b,c); VALUES=3,2,1] F1 FACTOR [LEVELS=!(11,12); LABELS=!t(d,e); VALUES=12,11] F2 FACTOR [LEVELS=3; LABELS=!t(f,g,h); VALUES=1] F3 " old factors only have labels and incompatible levels: matching by levels " APPEND [NEWVECTOR=Newfac1] F1,F2,F3 " old factors only have labels and incompatible levels: matching by labels " APPEND [NEWVECTOR=Newfac2; FREP=labels] F1,F2,F3 PRINT 2(Newfac1,Newfac2); FREPRESENTATION=labels,levels