interp {biogas}R Documentation

Interpolate Biogas Composition or Cumulative Production


interp interpolates (or extrapolates) biogas composition (methane concentration) or cumulative production data to a wanted time using one of several possible methods.


interp(times, y, time.out, method = "linear", extrap = FALSE)



measurement times. Numeric vector or POSIX.


response variable at times, e.g., mole fraction of methane in biogas, or biogas cumulative production. Numeric vector.


time or times at which interpolated values are needed. Numeric vector or POSIX.


method used for interpolation. Default is "linear", which uses the approx function. Use "f1" for to always use nearest value to right (see f = 1 argument in approx). For spline interpolation, use "ffm" or the other options available (see spline).


should y be exptrapolated? Logical. Default is FALSE. See ‘Details’.


interp is really a wrapper for the interpolation functions approx and spline. For cumulative production, which (usually) must monotonically increase, method = "hyman" is the best choice. Extrapolation behavior depends on method. For method = "linear", extrap = TRUE simply returns the value of the closest y. For manometric measurement with mix of venting/no venting with composition measurements only when venting use method = "f1". See approx and spline for more information.


Interpolated estimates of y at given times.


Sasha D. Hafner and Charlotte Rennuit

See Also



# Fake composition data 
dat <- data.frame(time = c(1, 7, 14, 28), 
                  xCH4 = c(0.3, 0.5, 0.61, 0.65))
interp(dat$time, dat$xCH4, time.out = 10)
interp(dat$time, dat$xCH4, time.out = 10, method = "natural")
interp(dat$time, dat$xCH4, time.out = c(10, 30))
interp(dat$time, dat$xCH4, time.out = c(10, 30), method = "natural")
interp(dat$time, dat$xCH4, time.out = c(10, 30), extrap = TRUE)

# Actual data
# Work with one reactor
bgc <- subset(comp, id=="2_1")

# With numeric time, interpolate to 1, 7, and 30 days
interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30))

# If extrapolation is OK
interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30), extrap = TRUE)

# Or POSIXct
interp(bgc$date.time, bgc$xCH4, 
       time.out = as.POSIXct("2014-07-12 13:00:00"))

# For cumulative gas production
# Work with one reactor
bgv <- subset(vol, id=="2_1")
# Calculate cumulative volume
bgv <- cumBg(bgv, = "days")
# The interpolate of cumulative production to 1, 7, and 30 days
interp(bgv$days, bgv$cvBg, time.out = c(1, 7, 30), method = "hyman")

[Package biogas version 1.23.2 Index]