In general it works best if you
- follow the advice in the FAQ
- specify the exact error you get
Do you mean something like this:
library(dplyr)
library(tibble)
db1 <- tibble::tribble(
~N_GEN, ~CAPTURE, ~CUM_ADULTI_SV, ~CUM_ADULTI_G1, ~CUM_ADULTI_G2, ~A1, ~A2, ~A3,
1, 0, 0.1, 0.01, 0.001, 1, 0.1, 0.3,
1, 1, 0.5, 0.1, 0.05, 2, 0.5, 0.8,
1, 0, 1, 0.5, 0.1, 2.5, 1, 1,
1, 5, 1.2, 0.8, 0.5, 3, 1.5, 1.2,
2, 1, 1.5, 1, 0.9, 4, 2, 1.8,
2, 2, 1.8, 1.2, 1, 5, 3, 2,
2, 7, 2, 1.5, 1.1, 5.5, 3.2, 2.1,
2, 9, 2.1, 1.6, 1.2, 5.6, 3.5, 2.9,
3, 1, 2.2, 1.7, 1.5, 6, 4, 3,
3, 2, 2.5, 2, 1.8, 7, 5, 4,
3, 7, 3, 3, 3, 9, 7, 5,
3, 10, 3.5, 4, 3.5, 9.3, 8, 6
)
db2 <- db1 |>
group_by(N_GEN) |>
mutate(AR1 = CUM_ADULTI_SV*(sum(CAPTURE)/sum(A1)),
AR2 = CUM_ADULTI_G1*(sum(CAPTURE)/sum(A2)),
AR3 = CUM_ADULTI_G2*(sum(CAPTURE)/sum(A3))
)