interpolate: Fills missing obs values by interpolation

View source: R/interpolate.R

interpolateR Documentation

Fills missing obs values by interpolation

Description

Missing (NA) values in a CRHMr obs data frame are filled by linear or spline interpolation. The user can set the maximum gap length (in time steps) allowed to be filled. Note that this function will NOT interpolate RH or precipitation values.

Usage

interpolate(
  obs,
  varcols = 1,
  methods = "linear",
  maxlength = 5,
  quiet = TRUE,
  logfile = ""
)

Arguments

obs

Required. The CRHMr data frame of obs values.

varcols

Optional. A vector containing the columns to be imputed in the obs data frame, not including the datetime. If not specified, defaults to the first column.

methods

Optional. A vector containing the methods to be used for interpolation for each of the variables. Currently supported methods are linear and spline. The default is to use linear interpolation. If fewer methods than columns are specified, the methods are recycled.

maxlength

Optional. The maximum gap length to be interpolated. Defaults to 5 time steps.

quiet

Optional. Suppresses display of messages, except for errors. If you are calling this function in an R script, you will usually leave quiet=TRUE (i.e. the default). If you are working interactively, you will probably want to set quiet=FALSE.

logfile

Optional. Name of the file to be used for logging the action. Normally not used.

Value

If successful, returns a modified version of the obs data frame. The missing values in the specified data frame are replaced by interpolated values. If unsuccessful, returns an error.

Note

In addition to the usual notation in the logfile, this function also writes a separate logfile which summarises the original obs data frame, and the new infilled data frame. The summaries are also printed to the screen, if quiet=FALSE. The logfile also contains a complete listing of the source of each value in the infilled data frame. Each value is listed as being original (unmodified from the primary obsframe), linear interpolation (infilled by linear interpolation), spline interpolation (infilled by spline interpolation) or NA (missing).

Author(s)

Kevin Shook

See Also

impute distributeP

Examples

## Not run: 
v.filled <- interpolate(v, c(1, 3))

## End(Not run)

CentreForHydrology/CRHMr documentation built on April 6, 2024, 5:27 p.m.