[R] predict.lm removes rownames for a single row. Why?
Richard M. Heiberger
rmh at temple.edu
Fri Jan 4 23:13:25 CET 2008
predict.lm keeps row names when working from several rows in
newdata, but always removes rowname from a single row.
The rownames are removed by the line in predict.lm
predictor <- drop(X[, piv, drop = FALSE] %*% beta[piv])
What is the reason for that decision? I usually want to
retain the row names.
tmp <- data.frame(x=1:4, y=c(1,3,2,5))
tmp.lm <- lm(y ~ x, data=tmp)
tmp.new <- data.frame(x=5:6, y=8:7)
predict(tmp.lm, newdata=tmp.new, interval="confidence") ##
rownames
predict(tmp.lm, newdata=tmp.new[1,,drop=FALSE], interval="confidence")## no
rownames
More information about the R-help
mailing list