Tests each element of inputVector using the given test. Puts into resultVector a list of the position numbers ("tags") of the elements that pass the test. The position number of the first element of the input vector is one.
You can use the list of positions in the resultVector with the TAKE command if you want to create a list of the actual elements that passed the test. If you want a list of the elements that didn't pass the test you can use the resultVector with the REMOVE command. If you use the TAGS and TAKE commands in tandem, or the TAGS and REMOVE commands in tandem, you can get the equivalent of the WEED command. See the second and third examples at right.
This program shows the effect of the TAGS command:
COPY (12.0 13.0 10.0 18.0 11.0 19.0 16.0 17.0 15.0 20.0 14.0) data TAGS data between 12 19 tags PRINT data tags
Here is the output from the above program:
data: (12.0 13.0 10.0 18.0 11.0 19.0 16.0 17.0 15.0 20.0 14.0) tags: (1.0 2.0 4.0 6.0 7.0 8.0 9.0 11.0)
The next example uses the TAGS command to copy only the odd numbers from one vector containing both even and odd numbers into another vector.
'To gather all the odd elements from a vector: COPY 1,20 vec 'all are integers REMAINDER vec 2 vec2 TAGS vec2 = 1 oddPositions TAKE vec oddPositions vecOdd PRINT vecOdd
and its output:
vecOdd: (1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0)
If you have a set of related data such as height, weight, and sex for a number of individuals, you might want to select a subset that meets certain criteria. For example, say you wanted the subset consisting of all individuals whose height is less than or equal to 65 inches. For this, you can use the TAGS command in conjunction with the TAKE command as follows:
NAME male female
COPY (62 68 73 58 66) height
COPY (120 165 198 99 115) weight
COPY (female male male female female) sex
TAGS height <=65 heightTags
TAKE height heightTags filteredHeight
TAKE weight heightTags filteredWeight
TAKE sex heightTags filteredSex
PRINT table filteredHeight filteredWeight filteredSex
The TAGS command puts the position numbers of all the elements of height that are less than or equal to 65 into the vector heightTags. Then those tags are used to copy the tagged elements from each related vector into a new vector. The output of this program is:
filteredHeight filteredWeight filteredSex
62 120 female
58 99 female
The following program illustrates the operation of the TAGS command and the fact that combining the TAGS command with the REMOVE command can be equivalent to the WEED command. This isn't something you should or should not do; it is just to show the equivalence.
'Shows equivalence between WEED and TAGS+REMOVE commands COPY 10,20 data TAGS data < 14 tags REMOVE data tags tagRemoveResult WEED data < 14 weedResult 'Note same test as in TAGS PRINT data tags tagRemoveResult weedResult
The result of the above program is:
data: (10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0) tags: (1.0 2.0 3.0 4.0) tagRemoveResult: (14.0 15.0 16.0 17.0 18.0 19.0 20.0) weedResult: (14.0 15.0 16.0 17.0 18.0 19.0 20.0)
The next program is similar to the previous one except it shows that combining TAGS with TAKE can be equivalent to the WEED command. In this case, however, the tests in the TAGS and the WEED commands must be complementary.
'Shows equivalence between WEED and TAGS+TAKE commands COPY 10,20 data TAGS data >= 14 tags TAKE data tags tagTakeResult WEED data < 14 weedResult 'Note complementary test to TAGS PRINT data tags tagTakeResult weedResult
The result of the above program is:
data: (10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0) tags: (5.0 6.0 7.0 8.0 9.0 10.0 11.0) tagTakeResult: (14.0 15.0 16.0 17.0 18.0 19.0 20.0) weedResult: (14.0 15.0 16.0 17.0 18.0 19.0 20.0)