series_fill_linear()series_fill_linear()

以线性方式将缺失值内插到序列中。Linearly interpolates missing values in a series.

采用包含动态数值数组作为输入的表达式,对 missing_value_placeholder 的所有实例执行线性内插,并返回生成的数组。Takes an expression containing dynamic numerical array as input, does linear interpolation for all instances of missing_value_placeholder, and returns the resulting array. 如果数组的开头和结尾包含 missing_value_placeholder,则它会替换为除 missing_value_placeholder 之外的最接近值。If the beginning and end of the array contain missing_value_placeholder, then it will be replaced with the nearest value other than missing_value_placeholder. 此功能可以关闭。This feature can be turned off. 如果整个数组都由 missing_value_placeholder 组成,则数字会使用 constant_value 进行填充,如果未指定,则使用 0 进行填充。If the whole array consists of the missing_value_placeholder, the array will be filled with constant_value, or 0 if not specified.

语法Syntax

series_fill_linear(x[, missing_value_placeholder [,fill_edges [,constant_value]]]))series_fill_linear(x[, missing_value_placeholder [,fill_edges [,constant_value]]]))

  • 将使用指定参数返回 x 的序列线性内插。Will return series linear interpolation of x using specified parameters.

参数Arguments

  • x:动态数组标量表达式(数值数组)。x : dynamic array scalar expression, which is an array of numeric values.
  • missing_value_placeholder:可选参数,用于指定要替换的“缺失值”的占位符。missing_value_placeholder : optional parameter, which specifies a placeholder for the "missing values" to be replaced. 默认值为 double(null)。Default value is double( null ).
  • fill_edges:布尔值,指示是否应将数组开头和结尾处的 missing_value_placeholder 替换为最接近值。fill_edges : Boolean value, which indicates whether missing_value_placeholder at the start and end of the array should be replaced with nearest value. 默认值为 True。True by default. 如果设置为 false,则会保留数组开头和结尾处的 missing_value_placeholder。If set to false , then missing_value_placeholder at the start and end of the array will be preserved.
  • constant_value:仅与数组相关的可选参数完全由 null 值组成。constant_value : optional parameter relevant only for arrays entirely consists of null values. 此参数指定用于填充序列的常数值。This parameter specifies a constant value to fill the series with. 默认值为 0。Default value is 0 . 将此参数设置为 double(null) 实际上会将 null 值保留在原处。Setting this parameter it to double( null ) will effectively leave null values where they are.

说明Notes

  • 若要在 make-series 之后应用任何内插函数,请指定“null”作为默认值:To apply any interpolation functions after make-series, specify null as the default value:

    make-series num=count() default=long(null) on TimeStamp from ago(1d) to ago(1h) step 1h by Os, Browser
    
  • missing_value_placeholder 可以是转换为实际元素类型的任何类型。The missing_value_placeholder can be of any type that will be converted to actual element types. 因此,无论“double(null)”、“long(null)”或“int(null)”都具有相同的含义。As such, either double( null ), long( null ) or int( null ) have the same meaning.

  • 如果 missing_value_placeholder 为 double(null)(或省略,这样含义相同),则结果可能包含 null 值。If missing_value_placeholder is double( null ) (or omitted, which have the same meaning) then a result may contain null values. 使用其他内插函数填充这些 null 值。Use other interpolation functions to fill these null values. 目前只有 series_outliers() 支持输入数组中有 null 值。Currently only series_outliers() support null values in input arrays.

  • 此函数会保留数组元素的原始类型。The function preserves original type of array elements. 如果 x 只包含 int 或 long 元素,则线性内插会返回舍入的内插值,而不是确切值。If x contains only int or long elements, then the linear interpolation will return rounded interpolated values rather than exact ones.

示例Example

let data = datatable(arr: dynamic)
[
    dynamic([null, 111.0, null, 36.0, 41.0, null, null, 16.0, 61.0, 33.0, null, null]), // Array of double    
    dynamic([null, 111,   null, 36,   41,   null, null, 16,   61,   33,   null, null]), // Similar array of int
    dynamic([null, null, null, null])                                                   // Array with missing values only
];
data
| project arr, 
          without_args = series_fill_linear(arr),
          with_edges = series_fill_linear(arr, double(null), true),
          wo_edges = series_fill_linear(arr, double(null), false),
          with_const = series_fill_linear(arr, double(null), true, 3.14159)  

arr without_args with_edges wo_edges with_const
[null,111.0,null,36.0,41.0,null,null,16.0,61.0,33.0,null,null][null,111.0,null,36.0,41.0,null,null,16.0,61.0,33.0,null,null] [111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0][111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0] [111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0][111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0] [null,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,null,null][null,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,null,null] [111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0][111.0,111.0,73.5,36.0,41.0,32.667,24.333,16.0,61.0,33.0,33.0,33.0]
[null,111,null,36,41,null,null,16,61,33,null,null][null,111,null,36,41,null,null,16,61,33,null,null] [111,111,73,36,41,32,24,16,61,33,33,33][111,111,73,36,41,32,24,16,61,33,33,33] [111,111,73,36,41,32,24,16,61,33,33,33][111,111,73,36,41,32,24,16,61,33,33,33] [null,111,73,36,41,32,24,16,61,33,null,null][null,111,73,36,41,32,24,16,61,33,null,null] [111,111,74,38, 41,32,24,16,61,33,33,33][111,111,74,38, 41,32,24,16,61,33,33,33]
[null,null,null,null][null,null,null,null] [0.0,0.0,0.0,0.0][0.0,0.0,0.0,0.0] [0.0,0.0,0.0,0.0][0.0,0.0,0.0,0.0] [0.0,0.0,0.0,0.0][0.0,0.0,0.0,0.0] [3.14159,3.14159,3.14159,3.14159][3.14159,3.14159,3.14159,3.14159]