Sequences of NA
values, are filled by linear interpolation between
the non-NA
values that bound the gap.
Usage
fillGap(x, method = c("linear"), rule = 1)
Arguments
- x
an oce object.
- method
to use; see “Details”.
- rule
integer controlling behaviour at start and end of
x
. Ifrule=1
,NA
values at the ends are left in the return value. Ifrule=2
, they are replaced with the nearest non-NA point.
Bugs
Eventually, this will be expanded to work with any
oce
object. But, for now, it only works for vectors that can be coerced to numeric.If the first or last point is
NA
, thenx
is returned unaltered.Only method
linear
is permitted now.
Examples
library(oce)
# Integers
x <- c(1:2, NA, NA, 5:6)
y <- fillGap(x)
print(data.frame(x, y))
#> x y
#> 1 1 1
#> 2 2 2
#> 3 NA 3
#> 4 NA 4
#> 5 5 5
#> 6 6 6
# Floats
x <- x + 0.1
y <- fillGap(x)
print(data.frame(x, y))
#> x y
#> 1 1.1 1.1
#> 2 2.1 2.1
#> 3 NA 3.1
#> 4 NA 4.1
#> 5 5.1 5.1
#> 6 6.1 6.1