Appends a list of vectors of the same type (R.W. Payne).
Options
NEWVECTOR = vector |
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 vector to which each unit originally belonged |
Parameter
OLDVECTOR = vectors |
Vectors whose values are to be appended together |
|---|
Description
APPEND provides a convenient way of putting the values from several vectors, all into a single vector. The new vector will contain all the values of the first vector, then all those from the second vector, and so on. The vectors can thus contain different numbers of values but they must all be of the same type: all variates, all factors or all texts.
The vectors whose values are to be appended together are specified by the OLDVECTOR parameter, and the NEWVECTOR option supplies the vector to store the appended values. If NEWVECTOR is omitted, the values are placed into the first OLDVECTOR.
For factors, the FREPRESENTATION option indicates how the levels are to be matched amongst the old vectors. 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 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
Any restrictions on the vectors are ignored.
See also
Directive: EQUATE.
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