You can do this clleanly with the map function from the purrr package.
See this vignette for an example.
library(dplyr)
library(purrr)
###Inventing some data
DF <- data.frame(pad = runif(100, min = 0, max = 10),
mad = runif(100, min = 0, max = 10),
noise = runif(100),
ubica = rep(1:10, each = 10))
#Calculate the inf column with known coef
DF <- DF %>% mutate(inf = 3 * pad - 2 * mad + 2.3 + noise)
###
FITS <- DF %>% split(.$ubica) %>%
map(~lm(inf ~ pad + mad, data = .)) %>%
map(summary)
FITS$`1`
#>
#> Call:
#> lm(formula = inf ~ pad + mad, data = .)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -0.47000 -0.19139 0.03641 0.20225 0.49864
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 2.90177 0.36210 8.014 9.02e-05 ***
#> pad 2.97840 0.05238 56.866 1.36e-10 ***
#> mad -2.01318 0.04507 -44.670 7.36e-10 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.3606 on 7 degrees of freedom
#> Multiple R-squared: 0.9986, Adjusted R-squared: 0.9983
#> F-statistic: 2570 on 2 and 7 DF, p-value: 9.28e-11
Created on 2020-06-15 by the reprex package (v0.3.0)