Aligning Data frame with missing values

后端 未结 4 1412
盖世英雄少女心
盖世英雄少女心 2020-12-04 00:31

I\'m using a data frame with many NA values. While I\'m able to create a linear model, I am subsequently unable to line the fitted values of the model up with

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 00:56

    I use a simple for loop. The fitted values have an attribute (name) of the original row they belonged to. Therefore:

    for(i in 1:nrow(data)){
      data$fitted.values[i]<-
        fit$fitted.values[paste(i)]
    }
    

    "data" is your original data frame. Fit is the object from the model (i.e. fit <- lm(y~x, data = data))

提交回复
热议问题