r_pick(C;S;I)

Returns the value of the column at the specified index within a given set of columns.

Function type

Vector only

Syntax

r_pick(C;S;I)

Input

Argument Type Description
C any A space- or comma-separated list of column names

C may also be a string expression (in single quotes) constituting a pattern for matching columns. For instance, 'foo*' specifies all columns that begin with "foo".

If C is omitted, the values in all of the columns are included.

Note: The columns specified by C must be either all numeric (integer and decimal) or all text.
S integer A boolean column or an expression in rcv_/rcn_/rct_ which determines whether or not that column is selected to be included in the calculation. See System variables for more information about rcv_/rcn_/rct_.

If S is omitted, all columns will be considered by the function (subject to any prior column selections).

I any A scalar value or the name of a column

If I is omitted, an error is returned.

Return Value

For each row of the table, r_pick returns the value of the column at index I within the group of columns specified by C.

If I does not match the type of the columns specified by C (i.e., numeric or text), an error is returned.

If there is no match, the result is N/A.

Sample Usage

c1 c2 c3 c4 r_pick(;;2) r_pick(c1 c3;;2) r_pick(c2 c3 c4;;c1)
2 5 7 2 5 7 7
7 7 4 1 7 4 NA
NA 0 9 3 0 9 NA
NA NA NA NA NA NA NA

Example

<base table="pub.demo.weather.hourly90"/>
<willbe name="b1" value="hour"/>
<willbe name="b2" value="date"/>
<willbe name="b3" value="id"/>
<willbe name="rand" value="draw(12131;0)"/>
<willbe name="ind" value="if(rand<.3;1;rand<.6;2;3)"/>
<willbe name="pick" value="r_pick('b*';;ind)"/>
<willbe name="pick2" value="r_pick(b1 b2 b3;;ind)"/>
<colord cols="b1,b2,b3,rand,ind,pick,pick2"/>