Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:47:47+00:00 2026-06-08T13:47:47+00:00

I think I’m on to a good idea, but don’t know how to implement

  • 0

I think I’m on to a good idea, but don’t know how to implement it. I am currently running a number of nested models. For example:

y<-c(1, 0, 1, 1, 1, 1, 1, 1, 0)
x1<-c(1, 0, 9, 9, 1, 9, 2, 1, 0)
x2<-c(1, 2, 3, 5, 4, 2, 4, 5, 1)
x3<-c(1, 2, 1, 4, 1, 3, 4, 8, 3)

model1 <-lm(y~x1)
model2 <-lm(y~x1+x2)
model3 <-lm(y~x1+x2+x3)

model1_output<-(summary(model1 )$coefficients[1])
model2_output<-(summary(model1 )$coefficients[1])
model3_output<-(summary(model1 )$coefficients[1])

I would then like to put all of my output in a data table that matches along the rows (variable names) but inserts the new coefficients in their own columns. I’d like the data.frame presenting the output from my example as:

             b(Model 1)  b(Model 2) b(Model 3)
 (Intercept)  0.59217    0.2555     0.27983
 x1           0.05220    0.04116    0.0375
 x2              NA      0.12530    0.15142
 x3              NA      NA        -0.02994

I’m sure there must be some smart way to do this using the plyr() package (or some other package!), but can’t seem to figure it out. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:47:48+00:00Added an answer on June 8, 2026 at 1:47 pm

    Using this answer from another question:

    cbind.fill<-function(...){
        nm <- list(...) 
        nm<-lapply(nm, as.matrix)
        n <- max(sapply(nm, nrow)) 
        do.call(cbind, lapply(nm, function (x) 
        rbind(x, matrix(, n-nrow(x), ncol(x))))) 
    }
    

    You could do this:

    do.call(cbind.fill,lapply(list(model1,model2,model3),function(x){coef(x)}))
    
                      [,1]       [,2]        [,3]
    (Intercept) 0.59216966 0.25551154  0.27982881
    x1          0.05220228 0.04116431  0.03754457
                        NA 0.12530141  0.15142340
                        NA         NA -0.02993768
    

    And then set the row and column names manually. (Note that this returns a matrix, not a data frame, if that matters to you.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
I think I have a basic understanding of this, but am hoping that someone
I think everyone knows this site http://pinterest.com/ and I don't want to create site
I think this could be a very easy question for you. But I have
I think that asking this might be kind of silly but I'm still wondering
I think it will be very hard for you to read the code but
I think this has probably been asked, but after reading a lot, I'm not
Think I have an activity with some layouts, I want to know is it
think this should be an easy one... I want to get the currently selected
I think they are same thing but my boss say that is not right.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.