Skip to content
Prev 373315 / 398498 Next

Problems with "predict" function

Your messages about masking come from attaching your data set to the R session. In general, that is bad practice as it leads to confusing code. It is typically better to use the ?data? argument in things like lm() to accomplish this task. 

As near as I can tell, your second set of predictions is not working because your call to lm() directly references vectors from the highdf data frame. If you do this:

h.lm <- lm(sales ~ month, data = highdf)
news <- data.frame(month = nrow(ptr) + 1)
hcs <- predict(h.lm, news, interval = "predict")

You should see the expected results. Note that here I?m directly referring to the variables ?sales? and ?month? and not using the bracket notation.