Excerpt |
---|
Computes the positive or negative sign of a given numeric value. The value can be a Decimal or Integer literal, a function returning Decimal or Integer, or a reference to a column containing numeric values. |
- For positive values, this function returns
1
. - For negative values, this function returns
-1
. - For the value
0
, this function returns 0
.
Column reference example:
D lang syntax |
---|
RawWrangle | true |
---|
Type | ref |
---|
showNote | true |
---|
WrangleText | derive type:single value:sign(MyInteger) as:'sign_MyInteger' |
---|
|
sign(MyInteger) |
Output: Returns the sign of the value found in the MyInteger
column.
Numeric literal example:
D lang syntax |
---|
RawWrangle | true |
---|
Type | ref |
---|
showNote | true |
---|
WrangleText | delete row:(sign(MyInteger) == -1) |
---|
|
(sign(MyInteger) == -1) |
Output: Returns true
if the sign of the entry in the MyInteger
column is -1
.
D lang syntax |
---|
RawWrangle | true |
---|
Type | syntax |
---|
showNote | true |
---|
WrangleText | derive type:single value:sign(numeric_value) |
---|
|
sign(numeric_value) |
Argument | Required? | Data Type | Description |
---|
numeric_value | Y | Decimal or Integer | Decimal or Integer literal, function returning Decimal or Integer, or name of column to apply to the function |
numeric_value
Numeric literal, function returning numeric literal, or name of the column containg values the sign of which are to be computed.
- Missing input values generate missing results.
- Literal numeric values should not be quoted. Quoted values are treated as strings.
- Multiple columns and wildcards are not supported.
Required? | Data Type | Example Value |
---|
Yes | String (column reference) or Integer or Decimal value | -10.5 |
Example - Basic SIGN function
Source:
Your source data looks like the following, which measures coordinate distances from a fixed point on a grid:
X | Y |
---|
-2 | 4 |
-6.2 | -2 |
0 | -4.2 |
4 | 4 |
15 | -0.05 |
Transformation:
You can use the following transform to derive the sign values of these columns:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'signX' |
---|
Type | step |
---|
WrangleText | derive type:single value: sign(X) as: 'signX' |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | sign(X) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
D trans |
---|
RawWrangle | true |
---|
p03Value | 'signY' |
---|
Type | step |
---|
WrangleText | derive type:single value: sign(Y) as: 'signY' |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | sign(Y) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
Using these two columns, you can assign each set of coordinates into a quadrant. For ease of reading, the following has been broken into two separate tranformations:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'lower-right' |
---|
p06Name | Default value |
---|
WrangleText | case cases: [(signX == 1) && (signY == -1),'lower-right'],[(signX == 1) && (signY == 1),'upper-right'] default: 'line' as: 'q1' |
---|
p01Name | Condition type |
---|
p06Value | 'line' |
---|
p03Name | Case 01 - Value |
---|
p07Value | 'q1' |
---|
p04Value | (signX == 1) && (signY == 1) |
---|
SearchTerm | Conditional column |
---|
p07Name | New column name |
---|
Type | step |
---|
p05Name | Case 02 - Value |
---|
p01Value | Case on custom conditions |
---|
p02Name | Case 01 - Condition |
---|
p02Value | (signX == 1) && (signY == -1) |
---|
p05Value | 'upper-right' |
---|
p04Name | Case 02 - Condition |
---|
|
D trans |
---|
RawWrangle | true |
---|
p03Value | 'lower-left' |
---|
p06Name | Default value |
---|
WrangleText | case cases: [(signX == -1) && (signY == -1),'lower-left'],[(signX == -1) && (signY == 1),'upper-left'] default: 'line' as: 'q2' |
---|
p01Name | Condition type |
---|
p06Value | 'line' |
---|
p03Name | Case 01 - Value |
---|
p07Value | 'q2' |
---|
p04Value | (signX == -1) && (signY == 1) |
---|
SearchTerm | Conditional column |
---|
p07Name | New column name |
---|
Type | step |
---|
p05Name | Case 02 - Value |
---|
p01Value | Case on custom conditions |
---|
p02Name | Case 01 - Condition |
---|
p02Value | (signX == -1) && (signY == -1) |
---|
p05Value | 'upper-left' |
---|
p04Name | Case 02 - Condition |
---|
|
Then, you can merge the two columns together:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'quadrant' |
---|
Type | step |
---|
WrangleText | merge col:q1,q2 as:'quadrant' |
---|
p01Name | Columns |
---|
p01Value | q1,q2 |
---|
p02Name | Separator |
---|
p02Value | '' |
---|
p03Name | New column name |
---|
SearchTerm | Merge columns |
---|
|
Results:
X | Y | signX | signY | quadrant |
---|
-2 | 4 | -1 | 1 | upper-left |
-6.2 | -2 | -1 | -1 | lower-left |
0 | -4.2 | 0 | -1 | line |
4 | 4 | 1 | 1 | upper-right |
15 | -0.05 | 1 | -1 | lower-right |