Column Expressions
Formula Expression using columns in the Mark Panel
A formula expression can be used to specify a filter or a determination of a computed column in Mark Panel.
When used for filters, the result of the operation should be a logical value, and when used for computed columns such as $X, $Y, and $Size, the result should be a number. For $Shape and $Color, both numeric and string specifications are possible. Other computed columns should be specified as strings.
When the type of the result is invalid for a purpose, the operation is not guaranteed.
- Column names can be used as variables (e.g if the column name is
Val, you can useVal + 100,Val == "show", etc.) - A string has to be enclosed with
". If not, it is assumed to be a column name. - Usable types of value are Logical (true/false), string, 64-bit integer, and 64-bit floating point number. Those are auto-detected.
Available Operators
| Operator | Explanation |
|---|---|
| + | Addition operator |
| - | Subtraction operator |
| * | Multiplication operator |
| / | Division operator |
| % | Modulo operator |
| | or || | Logical OR operator |
| & or && | Logical product operator |
| ^ | Exclusive disjunction operator |
| == | Equal to operator |
| != | Not equal to operator |
| < | Less than operator. If it is a string, it is compared in lexicographic order. |
| <= | Less than or equal to operator. If it is a string, it is compared in lexicographic order. |
| > | Greater than operator. If it is a string, it is compared in lexicographic order. |
| >= | Greater than or equal to operators. For strings, compares in lexicographic order. |
| =~ | Regular expression operator. True if the string on the left side matches the regular expression on the right side. |
| =* | Wildcard operator. True if the string on the left side matches the wildcard specification on the right side. |
- Only addition and comparison are possible with strings.
- Addition with strings converts numeric and boolean values to strings and combines them.
1 / 2is0in integer arithmetic, so write1 / 2.0.
Available Functions
| Function | Explanation |
|---|---|
| abs(a) | Return absolute value. |
| sqrt(a) | Return the square root. |
| log(a) | Return the natural logarithm. |
| exp(a) | Return exponent. |
| hypot(a, b) | Return the Euclidean distance. |
| ifelse(cond, a, b) | Return a if cond is true, b if false. |
| real(a) | Realization |
| integer(a) | Integerization |
| string(a) | Stringification |
| decimal(a, b) | Return a string indicating the floating point value a rounded to b degits after the decimal point. |
| isna(a) | Return whether NA or not. |
| random(from, to) | Return a random number of decimals in the specified range. |
| floor(a) | Return the number rounded down to the nearest whole number. |
| ceil(a) | Return the number rounded up to the nearest whole number. |
| round(a) | Return the number rounded to the nearest whole number. |
Last modified April 17, 2024