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 8403299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:18:25+00:00 2026-06-09T22:18:25+00:00

This must be a really trivial question but I’m struggeling to get a solution.

  • 0

This must be a really trivial question but I’m struggeling to get a solution. Here is my problem:

this works

#I run a simple regression
 data(mtcars)
 dataf <- mtcars
 summary(fit1 <- lm(mpg ~ wt,  data=dataf))

#Then I merge the fitted values with the data frame
 dataf$fit <- fitted(fit1)

This (of course) doesn’t work

 dataf[2,]<-NA
 summary(fit2 <- lm(mpg ~ wt,  data=dataf))
#of course the NA value reduces my lm output
 dataf$fit2 <- fitted(fit2)

Error in `$<-.data.frame`(`*tmp*`, "fit2", value = c(23.3189679389035,  : 
replacement has 31 rows, data has 32

but how do I geht the second example to work? I tried a solution via the row.names in model.matrix() but this does not work when I include certain factors in my regression (this has been reported as a bug if I understand this correctly). Thank you for your kind help!

  • 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-09T22:18:26+00:00Added an answer on June 9, 2026 at 10:18 pm

    After some search I think I found an alternative

    dataf[2,]<-NA
    summary(fit2 <- lm(mpg ~ wt,  data=dataf, na.action="na.exclude"))
    dataf$fit2 <- fitted(fit2)
    

    should do the trick. right?

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

Sidebar

Related Questions

I know there must be a really simple answer to this question, but I
This must be really simple but just not getting my syntax right here. let's
I'm really pulling my hair out, this must be a simple problem, but I
I know SQL well but I must be missing something really dumb here. This
i'm sure this must be really simple or i'm missing the point, but how
This must be a really stupid question, but I'm still very green when it
This must be a really basic question: I am trying to use Matplotlib. Here's
This question must be really basic, but if you have any pointers I would
This must be really simple... Following examples on here and php.net, I'm trying to
This must be really obvious, but how do I make a winsock listen to

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.