sapply function code no longer working

is a screenshot, not an R object that can be reproduced. Lacking a reprex. See the FAQ, I made up some data and guessed that the first sapply worked and the second was not.

get_coef <- function(x) lm(x ~ mpg, data = mtcars) |> coef()
apply(mtcars[2:11],2,get_coef)
#>                   cyl      disp         hp       drat        wt       qsec
#> (Intercept) 11.260683 580.88382 324.082314 2.38248715  6.047255 15.3547689
#> mpg         -0.252515 -17.42912  -8.829731 0.06042994 -0.140862  0.1241366
#>                      vs          am       gear       carb
#> (Intercept) -0.67816541 -0.59149275 2.50626625  5.7787984
#> mpg          0.05553164  0.04966211 0.05879527 -0.1476459

Created on 2023-02-28 with reprex v2.0.2

1 Like