[Rd] Naming difference in cbind between S-Plus (PR#6515)

Duncan Murdoch dmurdoch at pair.com
Sat Jan 31 22:57:05 MET 2004


On Sat, 31 Jan 2004 22:27:21 +0100 (CET), you wrote:

>Naming difference in cbind between S-Plus and R.
>I think R is wrong.

I'm not sure if R is right or wrong, but I suspect the difference
isn't in cbind, it's elsewhere...

>abc <- data.frame(y=1:4, x=rnorm(4))
>abc.lm <- lm(y ~ x, data=abc)
>predict.lm(abc.lm, type="terms")  ## this is where R got the name "x"
>abc <- cbind(abc, d=abc$y - predict.lm(abc.lm, type="terms"))

... in the line above.  In S-PLUS, what does

abc$y - predict.lm(abc.lm, type="terms")

give?  In R it gives a matrix with the column name "x".  It makes
sense to me that using cbind on a matrix with named columns should
keep those column names.  

What does S-PLUS do in this case:

M <- matrix(1:4, 2, 2, dimnames=list(NULL, c('a', 'b')))
cbind(c=5:6,d=M)

R gives 

> M <- matrix(1:4, 2, 2, dimnames=list(NULL, c('a', 'b')))
> cbind(c=5:6,d=M)
     c a b
[1,] 5 1 3
[2,] 6 2 4

which seems reasonable to me, though I might like the name "d" to be
incorporated somehow.

Duncan Murdoch



More information about the R-devel mailing list