From dmurdoch at pair.com  Sat Jan 31 22:57:05 2004
From: dmurdoch at pair.com (Duncan Murdoch)
Date: Sat Jan 31 22:57:24 2004
Subject: [Rd] Naming difference in cbind between S-Plus (PR#6515)
In-Reply-To: <20040131212721.4F225F1B2@slim.kubism.ku.dk>
References: <20040131212721.4F225F1B2@slim.kubism.ku.dk>
Message-ID: <nk8o10dqsuap1nir5kokj9nume9ojj0rn5@4ax.com>

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


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