interpolate#

swordfish.function.interpolate()#

Fills in null values in a numeric vector using interpolation. By default, the function treats each element’s position (0, 1, 2, …, size(X)-1) in X as its x-coordinate when performing the interpolation. You can also provide custom x-coordinates through the index parameter.

Parameters:
  • X (Constant) – A numeric vector.

  • method (Constant, optional) –

    A string indicating how to fill the null values. It can take the following values and the default value is ‘linear’.

    • ’linear’: for null values surrounded by valid values, fill the null values linearly. For null values outside valid values, fill the null values with the closest valid values.

    • ’pad’: fill null values with existing values.

    • ’nearest’: fill null values with the closest valid values.

    Note

    When method = ‘nearest’ and limitDirection = ‘both’, if a null value is equidistant from nearest valid values on both sides, the system fills it using the value on the left.

    • krogh: fill null values with krogh polynomials.

  • limit (Constant, optional) – A positive integer indicating the maximum number of consecutive null values to fill.

  • inplace (Constant, optional) – A Boolean value indicating whether to update the input vector array. The default value is false, which means a new vector will be returned.

  • limitDirection (Constant, optional) – A string indicating the direction to fill null values. It can take the following values: ‘forward’, ‘backward’ and ‘both’. The default value is ‘forward’.

  • limitArea (Constant, optional) –

    A string indicating restrictions regarding filling null values. It can take the following values and the default value is empty string “”.

    • empty string: no restrictions.

    • inside: only fill null values surrounded by valid values.

    • outside: only fill null values outside valid values.

  • index (Constant, optional) – Specifies a numeric or temporal vector that must have the same length as X and cannot contain null values. When index is provided, the function performs interpolation using these values as x-coordinates and X as y-coordinates to fill in any missing values in X.

Returns:

A numeric vector with null values filled in.

Return type:

Constant