Кажется, что есть два варианта.
1: реструктурируйте свой код так, чтобы gather_predictions()
использовался в конце
library(tidyverse)
library(modelr)
#The 3 original models
mdisp <- lm(mpg ~ disp, mtcars)
mcyl <- lm(mpg ~ cyl, mtcars)
mhp <- lm(mpg ~ hp, mtcars)
# New model
m_all <- lm(mpg ~ hp + cyl + disp, mtcars)
# Gather predictions for all four models at the same time
mtcars_pred <- mtcars %>%
gather_predictions(mdisp, mcyl, mhp, m_all)
2: используйте bind_rows()
плюс еще один вызовдо gather_predictions()
library(tidyverse)
library(modelr)
#The 3 original models
mdisp <- lm(mpg ~ disp, mtcars)
mcyl <- lm(mpg ~ cyl, mtcars)
mhp <- lm(mpg ~ hp, mtcars)
# Get predictions from the first three models
mtcars_pred <- mtcars %>%
gather_predictions(mdisp, mcyl, mhp)
# New model
m_all <- lm(mpg ~ hp + cyl + disp, mtcars)
# Get the new model's predictions and append them
mtcars_pred <- bind_rows(mtcars_pred,
gather_predictions(data = mtcars,
m_all))