This is part of the dataset (named "ME1") I'm using (all variables are numeric):
Year AgeR rateM
1 1751 -1.0 0.241104596
2 1751 -0.9 0.036093609
3 1751 -0.8 0.011623734
4 1751 -0.7 0.006670552
5 1751 -0.6 0.006610552
6 1751 -0.5 0.008510828
7 1751 -0.4 0.009344041
8 1751 -0.3 0.011729740
9 1751 -0.2 0.010988005
10 1751 -0.1 0.015896107
11 1751 0.0 0.018190140
12 1751 0.1 0.024588340
13 1751 0.2 0.029801362
14 1751 0.3 0.044515912
15 1751 0.4 0.055240354
16 1751 0.5 0.088476758
17 1751 0.6 0.119045309
18 1751 0.7 0.167866571
19 1751 0.8 0.239244825
20 1751 0.9 0.329683010
21 1751 1.0 0.472448318
I want to use a linear model and save coefficients as follow:
male<-lm(ME1$rateM~exp(AgeR))
summary(male)
coeff <- summary(male)$coefficients[2]
The problem is that I need to repeat this procedure for every year (from 1751 to 2014) and I want to save all coefficients into one dataset like this:
Year coeff
1751 0.1556977
1752 0.0966664
...
2014 0.0420914
I don't know if I have to use a for-loop, lapply or something else. Can someone help me?
See Question&Answers more detail:os