I am trying to cumulate monthly precipitations by plot measurement dates. Plots were measured at uneven dates and have their own rain records on a separate df.
dfs:
precip=as.data.frame(cbind(id=c(1,1,1,1), date_met=c('2021-01-01', '2021-02-01', '2021-03-01', '2021-04-01'), precip=c(20, 23, 23, 23)))
precip=precip %>% mutate(precip=as.numeric(precip), date_met=ymd(date_met))
meas=as.data.frame(cbind(id=c(1,1,2), ini_date=c('2021-01-01', '2022-02-02', '2021-02-03'), fin_date=c('2022-02-02','2023-04-03','2022-02-03')))
meas=meas %>% mutate(ini_date=ymd(ini_date), fin_date=ymd(fin_date))
So far, I have been able to do the cumulation not considering the plot id which is not right.
Any helps is appreciated.
require(cropgrowdays)
yield <- meas|>
dplyr::mutate(swd= purrr::map2_dbl(ini_date, fin_date, function(x, y)
cumulative(precip, var = precip, startdate = x, enddate = y)))