Combines or omits “slices” of a multi-way data structure (table, matrix or variate).
||Structure whose values are to be combined; no default i.e. this option must be set|
||Structure to contain the combined values; no default i.e. this option must be set|
||Dimension number or factor indicating a dimension of the
||Dimension number or factor indicating the corresponding dimension of the
||These define positions in each
||These define positions in each
||Define weights by which the values from each
Sometimes you may wish to reclassify a table to have factors different from those that you used in its declaration.
COMBINE allows you to omit or to combine levels of the classifying factors. Furthermore, if you want to take just one level of a factor, you can copy the values into a table with one less dimensions.
You specify the original table using the
OLDSTRUCTURE option, and a table to contain the reclassified values using the
NEWSTRUCTURE option; if you have not already declared the new table, it will be declared implicitly. You must specify both of these options.
You can modify several of the classifying factors at a time. You list the factors of the original table with the
OLDDIMENSION parameter, and the equivalent factors of the new table with
NEWDIMENSION. An alternative way of doing this is to give a dimension number, specifying the position of the factor in the classifying set of the table; for the
NEWDIMENSION list, this requires that you have already declared the new table. You can even omit the list of dimensions if they would be in ascending numerical order.
NEWDIMENSION can also be set to 0 (to imply no corresponding new factor), allowing you to extract a single slice of a table into a table with fewer dimensions.
You use the
NEWPOSITIONS parameters to specify how this combining is to be done. These parameters specify a pair of vectors for each pair of old and new dimensions, listing positions within the old dimension and the corresponding positions to which they are mapped in the new dimension. The positions can be defined in terms of either the levels or the labels of the factor that classifies the dimension. If you omit the vector for one of the dimensions, it is assumed to contain each value once only, taken in the order in which they occur in the levels vector of the factor. You indicate a margin of the table by a missing value in a variate, or by a null string in a text. Values in the original table can be allocated to more than one place. In parallel with the vectors of positions, you can also use the
WEIGHTS parameter to specify a variate of weights by which the values are multiplied before being entered into the new table.
Although the main way in which you will use
COMBINE is likely to be for tables, you can also use it on rectangular matrices and even variates. For these, the dimensions can only be numbers: number 1 refers to the rows of a matrix, and 2 to the columns; number 1 refers to the rows (or units) of a variate. The position vectors refer to the labels vectors of matrices, which can be variates, texts or pointers; or they refer to the unit labels of a variate, which can be held in either a variate or a text. If a dimension has no labels vector, you use a variate to specify its positions; then each value of the variate gives the number of a row, column or unit. You can do the same also if the labels vector is something other than a variate: that is, a text or a pointer.
Any restrictions, for example on
NEWPOSITIONS variates, are ignored.
Commands for: Calculations and manipulation.
" Example COMB-1: Use of the COMBINE directive" TEXT [VALUES=Birmingham,London,Liverpool,Leeds,Manchester,Sheffield,\ Cardiff,Newport,Swansea,Aberdeen,Dundee,Edinburgh,Glasgow] Townname VARIATE [VALUES=1977,1978,1979,1980,1981,1982] Yearnum FACTOR [LABELS=Townname] Town FACTOR [LEVELS=Yearnum] Year TABLE [CLASSIFICATION=Town,Year] Sales READ Sales 618 601 784 720 863 921 1466 1502 1201 1773 1948 1910 816 859 820 938 1007 1158 461 479 452 536 510 548 662 632 758 721 893 837 531 569 615 624 607 593 757 743 785 816 783 737 294 303 346 377 368 351 416 461 478 462 497 520 608 635 672 692 685 723 343 391 358 366 418 470 714 751 710 763 788 830 916 922 956 988 970 1004 : " put the sales figures into a table classified by country and year " TEXT [VALUES=England,Wales,Scotland] Cname FACTOR [LABELS=Cname] Country TABLE [CLASSIFICATION=Country,Year] Csales COMBINE [OLDSTRUCTURE=Sales;NEWSTRUCTURE=Csales]\ OLDDIMENSION=Town ; NEWDIMENSION=Country ;\ NEWPOSITIONS=!T(6('England'),3('Wales'),4('Scotland')) PRINT Sales & Csales " put the sales figures into a table classified by country & year with 2-yearly totals " TEXT [VALUES='1977','1978','1977-78','1979','1980','1979-80',\ '1981','1982','1981-82'] Ytnam FACTOR [LABELS=Ytnam] Yearsums TABLE [CLASSIFICATION=Yearsums,Country] Salesum COMBINE [OLDSTRUCTURE=Sales;NEWSTRUCTURE=Salesum]\ OLDDIMENSION=Town,Year ; NEWDIMENSION=Country,Yearsums ;\ OLDPOSITIONS=*,!V((1977...1982)2) ;\ NEWPOSITIONS=!T(6('England'),3('Wales'),4('Scotland')),\ !T('1977','1978','1979','1980','1981','1982',\ 2('1977-78','1979-80','1981-82')) PRINT Salesum " add margins of totals to Salesum " MARGIN Salesum PRINT Salesum " use COMBINE to correct the margins for the Yearsum dimension " COMBINE [OLDSTRUCTURE=Salesum; NEWSTRUCTURE=Salesum]\ OLDDIMENSION=Yearsums; NEWDIMENSION=Yearsums;\ OLDPOSITIONS=!(1...9,3,6,9);\ NEWPOSITIONS=!(1...9,*,*,*) PRINT Salesum MATRIX [ROWS=4;COLUMNS=5;VALUES=101...120] Fullmat " form a matrix containing the transpose of the last 3 rows & columns " COMBINE [OLDSTRUCTURE=Fullmat;NEWSTRUCTURE=Subtrans]\ OLDDIMENSION=1,2 ; NEWDIMENSION=2,1 ;\ OLDPOSITIONS=!(2...4),!(3...5) ; NEWPOSITIONS=!(3...1) PRINT Fullmat & Subtrans