I would not use a for loop at all. Below are two ways, one with the map function from the purrr package and another with the lapply function from base R. The first step is to use the split function to make subsets of the data, one for every value of CName. This returns a *list*, which is a kind of vector, where each element is a data frame. There will be one data frame for every CName. Then you can use either map() or lapply() to walk along that *list* and apply the lm() function. In either case, you will get a *list* of results from lm(), one for each country. Then you can apply the coef() function to those fits to get the fit coefficient. In this case you want the second fit coefficient, which is the slope. That slope is labeled Year, meaning it is the fit coefficient associated with the Year.

I quickly invented some data, so the CNames are just letters and the Cases numbers are random, resulting in crazy slope values. Also, I fit to the raw cases values, not to log(Cases+1). You would want to make a column containing the log(Cases+1) values beforehand.

```
set.seed(1)
DF <- data.frame(Row = 1:25,
CName = rep(LETTERS[1:5], 5),
Year = rep(1980:1984, each = 5),
Cases = runif(25, min = 1000, max = 5000))
DF
#> Row CName Year Cases
#> 1 1 A 1980 2062.035
#> 2 2 B 1980 2488.496
#> 3 3 C 1980 3291.413
#> 4 4 D 1980 4632.831
#> 5 5 E 1980 1806.728
#> 6 6 A 1981 4593.559
#> 7 7 B 1981 4778.701
#> 8 8 C 1981 3643.191
#> 9 9 D 1981 3516.456
#> 10 10 E 1981 1247.145
#> 11 11 A 1982 1823.898
#> 12 12 B 1982 1706.227
#> 13 13 C 1982 3748.091
#> 14 14 D 1982 2536.415
#> 15 15 E 1982 4079.366
#> 16 16 A 1983 2990.797
#> 17 17 B 1983 3870.474
#> 18 18 C 1983 4967.624
#> 19 19 D 1983 2520.141
#> 20 20 E 1983 4109.781
#> 21 21 A 1984 4738.821
#> 22 22 B 1984 1848.570
#> 23 23 C 1984 3606.695
#> 24 24 D 1984 1502.220
#> 25 25 E 1984 2068.883
library(purrr)
DF2 <- DF %>% split(.$CName) %>% map( ~ lm(Cases ~ Year, data = .)) %>%
map(function(x){tmp <- coef(x); tmp[2]})
DF2
#> $A
#> Year
#> 375.0811
#>
#> $B
#> Year
#> -218.8078
#>
#> $C
#> Year
#> 195.4996
#>
#> $D
#> Year
#> -725.7537
#>
#> $E
#> Year
#> 338.6946
#Same thing with lapply
Fits <- DF %>% split(.$CName) %>%
lapply(FUN = function(x) lm(Cases ~ Year, data = x)) %>%
lapply(FUN = function(x) {tmp <- coef(x); tmp[2]})
Fits
#> $A
#> Year
#> 375.0811
#>
#> $B
#> Year
#> -218.8078
#>
#> $C
#> Year
#> 195.4996
#>
#> $D
#> Year
#> -725.7537
#>
#> $E
#> Year
#> 338.6946
```

^{Created on 2019-12-13 by the reprex package (v0.2.1)}