timeIntegration {Smisc} | R Documentation |
Integrate a series over time by calculating the area under the "curve" of the linear interpolation of the series (akin to the Trapezoid rule). This is especially useful in calculating energy usage: kilowatt-hours, watt-seconds, etc.
timeIntegration(data, time = names(data), lower = time[1], upper = time[length(time)], check.plot = FALSE, units = c("hours", "minutes", "seconds"))
data |
Vector of numerical data |
time |
Vector of timestamps which correspond to |
lower |
The time (character or POSIXct) of the lower bound of the integration |
upper |
The time (character or POSIXct) of the upper bound of the integration |
check.plot |
|
units |
The units of integration, defaults to hours. It is only required to supply enough characters to uniquely complete the name. |
If upper
or lower
does not correspond to a data point, a
linear interpolation is made between the two neighboring time points to
predict the resulting data value.
The approximation of the integral by joining the points in the series in a linear fashion and calculating the area under this "curve".
Landon Sego
# Some example power data data(PowerData) par(mfrow = c(2, 1)) # Calculate the kilowatt-minutes, display graph which shows how the # integration is done. This example calculates the integral using # a contiguous subset of the data int1 <- timeIntegration(PowerData, # Convert to POSIXct in order to subtract time lower = "5/6/2008 17:00:09", upper = "5/6/2008 17:01:36", check.plot = TRUE, units = "m") # This example calculates the integral for all the data in 'powerData' int2 <- timeIntegration(PowerData, check.plot = TRUE, units = "m") # Print the outcome pvar(int1, int2)