-1

I am new to R and was wondering if there was a way to add coefficients from different regression fits into a single tidy table?

Kind Regards,

Matt

phalteman
  • 3,442
  • 1
  • 29
  • 46
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 12 '19 at 16:08
  • Yes, there is. Details depend on the specific function your are using for fitting the model and for some types of models possibly even on the specific input. – Roland Dec 12 '19 at 16:11
  • Use `broom::tidy` on your models and you should be able to find a way to `rbind` (or `bind_rows`) them together. – Gregor Thomas Dec 12 '19 at 16:14
  • package stargazer – s_baldur Dec 12 '19 at 16:24

1 Answers1

0

You can try something like this if you only have a few models:

library(tidyverse)
library(broom)

mtcars %>% 
  glimpse()

mod1 <- lm(mpg ~ hp, data = mtcars)
mod2 <- lm(mpg ~ wt, data = mtcars)

mod1_tidy <- tidy(mod1) %>% mutate(model = 1)
mod2_tidy <- tidy(mod2) %>% mutate(model = 2)

bind_rows(mod1_tidy, mod2_tidy)
Giovanni Colitti
  • 1,982
  • 11
  • 24