I am putting everything from the comments into this answer.
1) You can use predict
rather than predict.lm
as predict
will know your input is of class lm
and do the right thing automatically.
2 The newdataset
should be a data.frame
with the same variables as your original predictors - in this case alt
and sdist
.
3) If you are bringing in you data using read.table
by default it will create a data.frame
. This assumes that the new data has columns named alt
and sdist
Then you can do:
NewDataSet<-read.table(whatever)
NewPredictions<- predict(model1, newdata=NewDatSet)
4) After you have done this if you want to check the predictions - you can do the following
summary(model1)
This will give you the intercept and the coefficients for alt
and sdist
NewDataSet[1,]
This should give you the alt
and sdist
values for the first row, you can change the 1 in the bracket to be any row you want. Then use the information from summary(model1)
to calculate what the predicted value should be using any method that you trust.
Finally use
NewPredictions[1]
to get what predict()
gave you for the first row (or change the 1 to any other row)
Hopefully that should all work out.