Special functions
Use functions to work with time series, fill gaps in missing data, write conditional statements, compute cumulative sums, and shift values in a series.
fill_missing()
Many synthetic expressions require two or more variables. In these cases, each value must have the same timestamp. Otherwise, the engine cannot compute the expression. fill_missing() helps by filling gaps where any variable in the expression has a missing value. The syntax is as follows:
fill_missing(expression, <first_fill>, <last_fill>, <fill_value>)
Expression
The expression to compute
N/A
YES
first_fill
Determines how the gap should be filled. By default, it is set to ffill.
ffill: Fills gaps forward, starting from the most recent data point.
bfill: Fills gaps backward, starting from the oldest data point.
None: No fill is applied.
NO
last_fill
Determines how the gap should be filled at the end of the time series. This is useful when you need to fill all gaps in the variables. By default, the function is set to none.
ffill: Fills gaps forward, starting from the most recent data point.
bfill: Fills gaps backward, starting from the oldest data point.
none: No fill is applied.
NO
fill_value
Value used to fill blanks in the variables.
Any integer or float.
NO
Examples
fill_missing(temperature * humidity)
Fills missing gaps, starting from the most recent data point in the temperature and humidity time series, and then calculates their product.
fill_missing(temperature * humidity, fill_value = 1)
Fills missing gaps with the value 1, starting from the most recent data point in the temperature and humidity time series, and then calculates their product.
fill_missing(temperature * humidity, "first_fill" = "bfill")
Fills missing gaps, starting from the oldest data point in the temperature and humidity time series, and then calculates their product.
where()
Some use cases require a conditional expression. The where() function is an if-else statement that executes one of two actions depending on whether the input condition is true or false. The syntax is as follows:
where(condition, operation if true, operation if false)
It computes operation_if_true when the condition is true. Otherwise, it executes operation_if_false.
diff()
This function calculates the difference between an element in a time series and another element separated by a specified number of steps. The syntax is as follows:
diff(<variable>,<steps>)
Variable
Represents the measurements of a sensor as a time series of data points that vary over time. Also known as "dots", it is identified by a variable label.
Variable label
YES
Steps
Number of positions separating two elements in the time series, starting from the most recent element.
Any positive integer no greater than the total number of elements in the time series
YES
shift()
This function returns the variable's values in the time series shifted by the given number of steps. The syntax is as follows:
shift(<variable>, <step>)
Variable
Represents the measurements of a sensor as a time series of data points that vary over time. Also known as "dots", it is identified by a variable label.
Variable label
YES
Step
Number of positions (+/-) by which the time series is shifted.
Positive or negative integer
YES
cumsum()
This function returns the cumulative sum of a time series. The syntax is:
cumsum(x), where x is the variable to calculate.
Last updated
Was this helpful?