I measured N20 flux from the soil at several points in time per day (uneven). I am trying to calculate the total N20 flux from the soil over several days by finding the area under the curve for a given day. I know how to do this using only measures from this day, however I would like to include the last measure of the previous day and the first measure of the next day to improve the curve estimate.
Here is an example to give a more specific idea:
library(MESS)
library(lubridate)
library(dplyr)
Create a reproducible example
datetime <- seq(ymd_hm('2015-04-07 11:20'),ymd('2015-04-13'), by = 'hours')
dat <- data.frame(datetime, day = day(datetime), Flux = rnorm(n = length(datetime), mean = 400, sd = 20))
useDate <- data.frame(day = c(7:12), DateGood = c("No", "Yes", "Yes", "No", "Yes", "No"))
dat <- left_join(dat, useDate)
"" ( ), - "" (). , (), "" , .
out <- dat %>%
mutate(lagDateGood = lag(DateGood),
leadDateGood = lead(DateGood)) %>%
filter(lagDateGood != "No" | leadDateGood != "No")
-
out2 <- out %>%
group_by(day) %>%
mutate(hourOfday = hour(datetime) + minute(datetime)/60) %>%
summarize(auc = auc(x = hourOfday, y = Flux, from = 0, to = 24, type = "spline"))
, AUC. , 10- , "" .
, . (, 8- AUC 8- 9- ). ? ?