interpolate
Syntax
interpolate(X, [method='linear'], [limit], [inplace=false],
[limitDirection='forward'], [limitArea])
Arguments
X is a numeric vector.
-
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.
-
krogh: fill null values with krogh polynomials.
limit is a positive integer indicating the maximum number of consecutive null values to fill.
inplace is 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 is 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 is 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.
Details
Fill the null values in a vector.
Examples
a=[NULL,NULL,1,2,NULL,NULL,5,6,NULL,NULL];
interpolate(a);
// output: [,,1,2,3,4,5,6,6,6]
interpolate(X=a, method="pad");
// output: [,,1,2,2,2,5,6,6,6]
interpolate(X=a, limitDirection='both');
// output: [1,1,1,2,3,4,5,6,6,6]
interpolate(X=a, limit=1, limitDirection='both');
// output: [,1,1,2,3,4,5,6,6,]
interpolate(X=a, limitDirection='both', limitArea='outside');
// output: [1,1,1,2,,,5,6,6,6]
a;
// output: [,,1,2,,,5,6,,]
interpolate(X=a, limitDirection='backward', inplace=true);
// output: [1,1,1,2,3,4,5,6,,]
a;
// output: [1,1,1,2,3,4,5,6,,]