interp {biogas} | R Documentation |
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)
times |
measurement times.
Numeric vector or |
y |
response variable at |
time.out |
time or times at which interpolated values are needed.
Numeric vector or |
method |
method used for interpolation.
Default is |
extrap |
should |
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
.
See approx
and spline
for more information.
Interpolated estimates of y
at given times
.
Sasha D. Hafner and Charlotte Rennuit
# 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 data(comp) # 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 data(vol) # Work with one reactor bgv <- subset(vol, id=="2_1") # Calculate cumulative volume bgv <- cumBg(bgv, time.name = "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")