[R] predict.lm removes rownames for a single row. Why?

From: Richard M. Heiberger <rmh_at_temple.edu>
Date: Fri, 4 Jan 2008 17:13:25 -0500

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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 04 Jan 2008 - 22:18:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jan 2008 - 07:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive