У вас есть несколько вариантов
d <- structure(list(
year = c(2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L,
2000L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L,
2001L, 2001L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L),
Concentration = c(19.01, 3.38, 7.78, 50.33, 0.04, 1.4, 5.11, 4.53, 9.57,
5.25, 2.33, 9.29, 4.01, 0.39, 1.14, 6.1, 1.19, 4.09, 1.89, 1.28,
5.96, 2.36, 5.47, 13.03, 6.57, 5.11, 0.65, 0.39, 3.35, 12.92,
10.01, 4.66, 2.25, 1.31, 1.13, 5.45, 6.4, 1.06, 3.09),
Precipitaion = c(23.7251908396947, 25.8842975206612, 12.9504950495049,
22.6153846153846, 19.063829787234, 67.8202247191011, 88.4383561643836,
42.7234042553192, 33, 21.3023255813953, 28.9491525423729,
42.7428571428571, 16.8813559322034, 125.093525179856, 50,
51.0909090909091, 25.0833333333333, 35.921568627451, 127.396226415094,
100.266666666667, 29.5922330097087, 49.0526315789474, 121.756097560976,
53.6978417266187, 23.7575757575758, 74.4375, 29.3592233009709,
180.512195121951, 20.5423728813559, 53.5789473684211, 24.5274725274725,
39.6363636363636, 13.6901408450704, 96.24, 13.1428571428571,
19.8347107438017, 57.375, 186, 59.2142857142857)),
class = "data.frame", row.names = c(NA, -39L))
. Простое решение - использовать split и lapply
user_function <- function(d) {
mean(rnorm(10000, mean = mean(d$Concentration), sd = sd(d$Precipitaion)))
}
lapply(split(d, d$year), user_function)