r_last(C;S)
Returns the last valid (non-N/A) value across a given set of columns.
Function type
Vector only
Syntax
r_last(C;S)
Input
Argument | Type | Description |
---|---|---|
C |
integer, decimal, or string | A space- or comma-separated list of column names
If |
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
|
Return Value
For each row of the table, r_last
returns a decimal value corresponding to
the last non-N/A value in the columns specified by C
.
If all the values in the columns specified by C
are N/A, the result is
N/A.
C
is a string, r_last
returns the last value, regardless of whether it is a N/A
value. To omit N/A values, you must explicitly omit them
using the S
argument. See the example
below.Sample Usage
c1 |
c2 |
c3 |
c4 |
r_last(;) |
r_last(c1 c2;) |
---|---|---|---|---|---|
2 | 5 | 7 | 2 | 2 | 5 |
7 | 7 | 4 | 1 | 1 | 7 |
NA | 0 | 9 | 3 | 3 | 0 |
NA | NA | NA | NA | NA | NA |
'foo' | 'bar' | 'baz' | NA | NA | |
'a' | 'b' | 'c' | NA | 'b' |
Example
In the following example, r_first(C;S)
and
r_last(C;S)
return the first and last valid
value in two rows containing strings. r_first(C;S)
and r_last(C;S)
use the S
argument
to omit N/A values.
<table>,foo,bar,baz;a,b,c,
</table>
<willbe name="not_na" value="string(rcv_)<>NA"/>
<willbe name="first" value="r_first(c1 c2 c3 c4;not_na)"/>
<willbe name="last" value="r_last(c1 c2 c3 c4;not_na)"/>