I have the following data example:
trap_data <- structure(list(site = c(1, 2, 3, 3), trap_date = structure(c(18809,
18809, 18307, 18322), class = "Date")), class = "data.frame", row.names = c(NA,
-4L))
climate <- structure(list(site = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3),
V1 = c(0.1, 0.2, 0.1, 0.1, 0.5, 0.2, 0.3, 0.1, 0.2, 0.1,
0.1, 0.5), V2 = c(1, 1, 3, 1, 2, 3, 3, 1, 1, 3, 1, 2), date = structure(c(18779,
18790, 18789, 18792, 18791, 18790, 18789, 18792, 18305, 18306,
18307, 18308), class = "Date")), class = "data.frame", row.names = c(NA,
-12L))
I would add columns in trap_data that summarize N, mean and sum, of V1 and V2 of climate data, conditioned by site and date. However, I would these new variables (N, mean and sum) are for the N days (these time lengths are variable. for example 20 current days) before the specified date in trap_data.
Thanks,