r - Predict() in wider range -


i sorry repeat question on , on seems have poor understanding in predicting wider range. seems if data's nrow matches predicting values have no error. however, if want predict different range getting error.

using same data dplyrdo-requires-named-function

it works well. if want change range of fitting getting error!

library(dplyr) iris %>%   group_by(species) %>%   do({     mod <- lm(sepal.length ~ sepal.width, data = .)     pred <- predict(mod, newdata = data.frame(sepal.width=seq(1,10,length.out=51)))     data.frame(., pred)   }) 

error in data.frame(., pred) : arguments imply differing number of rows: 50, 51

i understand new range not match previous data .. oth, need predict wider range of sepal.width values. possible ?

when use data.frame(.,pred) you're trying bind existing data frame 50 rows , new prediction 51 rows. if replace line data.frame(pred) works fine:

# tibble: 153 x 2 # groups:   species [3]    species     pred     <fctr>    <dbl>  1  setosa 3.329491  2  setosa 3.453779  3  setosa 3.578067  ... 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -