I am trying to use R to create a linear model and use that to predict some values. The subject matter is baseball stats. If I do this:
obp <- lm(offense$R ~ offense$OBP)
predict(obp, newdata=data.frame(OBP=0.5), interval="predict")
I get the error: Warning message: 'newdata' had 1 row but variables found have 20 rows.
However, if I do this:
attach(offense)
obp <- lm(R ~ OBP)
predict(obp, newdata=data.frame(OBP=0.5), interval="predict")
It works as expected and I get one result. What is the difference between the two? If I just print OBP and offense$OBP, they look the same.