# interpolate

Syntax

interpolate(array, [method=’linear’], [limit], [inplace=false], [limit_direction=’forward’], [limit_area])

Arguments

array is a numeric vector.

method is a string indicating how to fill the NULL values. It can take the following values and the default value is ‘linear’.

• linear: for NULLs surrounded by valid values, fill the NULLs linearly. For NULLs outside valid values, fill the NULLs 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.

limit_direction 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’.

limit_area 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 NULLs surrounded by valid values.

• outside: only fill NULLs 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);
[,,1,2,3,4,5,6,6,6]

[,,1,2,2,2,5,6,6,6]

\$ interpolate(array=a, limit_direction='both');
[1,1,1,2,3,4,5,6,6,6]

\$ interpolate(array=a, limit=1, limit_direction='both');
[,1,1,2,3,4,5,6,6,]

\$ interpolate(array=a, limit_direction='both', limit_area='outside');
[1,1,1,2,,,5,6,6,6]

\$ a;
[,,1,2,,,5,6,,]

\$ interpolate(array=a, limit_direction='backward', inplace=true);
[1,1,1,2,3,4,5,6,,]

\$ a;
[1,1,1,2,3,4,5,6,,]
```