interpolate: Interpolation

Description Usage Arguments Value Examples

View source: R/ff_interpolate.R

Description

This function applies interpolation to fill in missing (or non-recorded) values.

Usage

1
2
3
4
5
6
7
8
interpolate(
  x,
  col_name,
  out_name = NULL,
  miss_table,
  threshold,
  method = "linear"
)

Arguments

x

data frame with class Date or POSIXct in the first column and numeric on the others.

col_name

string with column name of the series to interpolate.

out_name

optional. String with new column name. If you set it as NULL, the function will overwrite the original data frame.

miss_table

data frame with three columns: first and last date of interpolation (first and second column respectively). The last and third column, is of class numeric with the number of steps to interpolate. See report_miss.

threshold

numeric variable with the maximum number of dates in which to apply the interpolation.

method

string with the interpolation method. In this version only 'linear' method is allowed.

Value

The same data frame but with interpolated values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# read cuevas station file
path <- system.file('extdata', 'ianigla_cuevas.csv',
        package = 'hydrotoolbox')

cuevas <- read_ianigla(path = path)

# get the miss_table
miss_data <- report_miss(x = cuevas, col_name = 'Irradiancia')[[1]]

# apply interpolation function when gap is less than 3 hours
cuevas_interpo <- interpolate(x = cuevas,
                              col_name = 'Irradiancia',
                              out_name = 'kin_interpo',
                              miss_table = miss_data,
                              threshold = 3)

report_miss(x = cuevas_interpo,
            col_name = c('Irradiancia', 'kin_interpo'))

hydrotoolbox documentation built on July 9, 2021, 1:06 a.m.