1

I have a dataframe with 13 columns. One is the predictor and rest of them are response variables. I want to fit a regression model to all the columns. I used the following code,

reg <- lapply( birthData[,-1], function(y) lm(y ~ birthData$Year) )

The problem is I have saved the coefficients in a variable and now I want to display the output as,

              Intercept            birthData$Year
Column A        value                   value
Column B        value                   value
.
.
.
.

So that it would be useful to display the results. Can anybody help me in doing this. The problem I am facing here is, I have to use reg$columnA$coefficients to get the values for the first column and for all the columns it is lot of coding. Is there a easy way to save it?

Observer
  • 641
  • 2
  • 14
  • 31
  • Welcome to stackoverflow (SO)! It's more likely that we will be able to help you if you make a minimal reproducible example to go along with your question. Something we can work from and use to show you how it might be possible to solve your problem. You can have a look at [this SO post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a great reproducible example in R. Furthermore, it would also be helpful if you outline what you have already tried. – Eric Fail Nov 29 '15 at 03:30
  • 1
    `do.call('rbind', lapply(reg, coef))` will probably get it – rawr Nov 29 '15 at 04:31

0 Answers0