any

Syntax

any(func, args...)

Arguments

func is a function.

args are the required parameters of func. They can be vectors/matrices/tables. They do not need to have the same data form, but they must have the same size. Data size is the number of elements for a vector, the number of columns for a matrix, and the number of rows for a table.

Details

Apply a function on each element of all arguments. The template runs through each element of a vector, each column of a matrix, and each row of a table. It stops execution and returns a true value as soon as one function call returns a true value. It returns a false value if all function calls return false values.

Examples

Template any on a vector:

x = 1 2 3 11 12 13 NULL 102 103;
y = x cut 3;
y;
// output
([1,2,3],[11,12,13],[,102,103])

any(hasNull, y);
// output
1
// check if any of [1,2,3],[11,12,13],[,102,103] has NULL values;

x=1 25 7 15 11 197 16 18 23;
y=x cut 3;
y;
// output
([1,25,7],[15,11,197],[16,18,23])

any(in, 7 8 23, y);
// output
1
// return true since 7 is in [1, 25, 7], although 8 is not in [15,11,197]

any(in, 8 20 19, y);
// output
0
// 8 is not in [1,25,7], 20 is not in [15,11,197], and 19 is not in [16,18,23]

any(lt, 4 5 6, 1 2 3);
// output
0
// check if 4<1, 5<2 and 6<3

any(<, 4 5 6, 1 7 3);
// output
1
// return true as 5<7 is true

Template any on a matrix. For a matrix, the template runs through each column.

x=1..6$2:3;
x;
#0 #1 #2
1 3 5
2 4 6
any(in, 6 1 4, x);
// output
0

any(in, 3 4 2, x);
// output
1
// return true as 4 is in the second column of matrix x

Template any on a table. For a table, the template runs through each row. In the following example, we define a function varscompare to compare the values of 2 variables in a table.

x=table(1 2 3 as a, 4 5 6 as b);
x;
a b
1 4
2 5
3 6
def varscompare(t): t.a>t.b;
any(varscompare, x);
// output
0

y=table(1 7 3 as a, 4 5 6 as b);
y;
a b
1 4
7 5
3 6
any(varscompare, y);
// output
1
//return true as 7>5 is true