Scripting > UNICOM Intelligence Function Library > Categorical functions > Difference
 
Difference
Returns the difference of two category lists--that is, it returns the categories that are in the first category list but not in the second. The categories are returned in the order in which they appear in the first category list.
Syntax
Difference(Val, Answers)
Parameters
Val
Type: Categorical
Categorical value.
Answers
Type: None
Variant value of type Categorical or Text, specifying a set of categories.
(return)
Type: Categorical
Set of categories that are in Val but not in Answers, in the order in which they appear in Val.
Remarks
If the current value is NULL, Val is an empty Categorical value ({}) and the return value is also an empty Categorical value. If Answers is NULL, the return value is Val.
This function is equivalent to the Subtraction (-) operator for Categorical values, except that Difference can operate on named categories and the NULL behavior is different. However, using the subtract (-) operator is generally faster than using the Difference function.
Examples
Function call
Q1
Q2
Result
Q1.Difference(Q2)
{1,2,3}
{4,5,6}
{1,2,3}
Q1.Difference(Q2)
{1,2,3,4,5,6}
{4,5,6}
{1,2,3}
Difference(Q1, Q2)
{1,2,3,4,5,6}
{3,6,4,1,2,5}
{}
Like Intersection and XUnion, Difference is useful when categorical variables have identical or overlapping category lists. For example, the remember and interest variables are categorical variables that have similar category lists. remember is a multiple response variable that records which galleries the respondents remember viewing, and interest is a single response variable that records which gallery respondents found most interesting. In the following example, the Difference function is used to remove the responses given to the interest question from the responses given to the remember question. The >= operator then tests whether the resulting list of categories includes the Fossils category. You could use this expression to create a filter to select respondents who remember the Fossils gallery, but who did not find it the most interesting gallery.
Difference(remember, interest) >= {FOSSILS}
For an example of using Difference in a data cleaning script, see Example 4: Cleaning other question types.
See also
Categorical functions