rmh@temple.edu
2004-Jan-31 22:27 UTC
[Rd] Naming difference in cbind between S-Plus (PR#6515)
Naming difference in cbind between S-Plus and R. I think R is wrong. 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")) abc R gives> abcy x x 1 1 -1.33925477 1.163001 2 2 1.52764505 1.799073 3 3 0.07805628 2.983086 4 4 -0.48720310 4.054840 S-Plus gives> abcy x d 1 1 1.8843692 2.075596 2 2 -0.9144517 1.296060 3 3 0.5063175 3.199408 4 4 -0.7054668 3.428936 Rich --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 1 minor = 7.1 year = 2003 month = 06 day = 16 language = R Windows XP Home Edition (build 2600) Service Pack 1.0 Search Path: .GlobalEnv, package:methods, package:ctest, package:mva, package:modreg, package:nls, package:ts, file:c:/HOME/rmh/hh/splus.library/.RData, package:grid, package:lattice, Autoloads, package:base
Duncan Murdoch
2004-Jan-31 22:57 UTC
[Rd] Naming difference in cbind between S-Plus (PR#6515)
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
Prof Brian Ripley
2004-Jan-31 23:00 UTC
[Rd] Naming difference in cbind between S-Plus (PR#6515)
>From ?cbindFor 'cbind' ('rbind') the column (row) names are taken from the names of the arguments, or where those are not supplied by deparsing the expressions given (if that gives a sensible name). The names will depend on whether data frames are included: see the examples. and you cbind-ed a data frame with columns y, x to a data frame with column x. It seems to me that what S-PLUS does is equally inconsistent: abc <- data.frame(y=1:4, x=rnorm(4)) d <- data.frame(x=1:4, e=5:8)> cbind(abc, d)y x x e ...> cbind(abc, d=d)y x d.x d.e ...> cbind(abc, d=d[1])y x d ...> cbind(abc, d[1])y x x ... and I would have expected the third to give the name d.x, not d and not x. Differences from S-PLUS (and please learn to write that correctly!) are not per se bugs in R. On Sat, 31 Jan 2004 rmh@temple.edu wrote:> Naming difference in cbind between S-Plus and R. > I think R is wrong. > > 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")) > abc > > > R gives > > abc > y x x > 1 1 -1.33925477 1.163001 > 2 2 1.52764505 1.799073 > 3 3 0.07805628 2.983086 > 4 4 -0.48720310 4.054840 > > S-Plus gives > > abc > y x d > 1 1 1.8843692 2.075596 > 2 2 -0.9144517 1.296060 > 3 3 0.5063175 3.199408 > 4 4 -0.7054668 3.428936 > > > Rich > > --please do not edit the information below-- > > Version: > platform = i386-pc-mingw32 > arch = i386 > os = mingw32 > system = i386, mingw32 > status = > major = 1 > minor = 7.1 > year = 2003 > month = 06 > day = 16 > language = R > > Windows XP Home Edition (build 2600) Service Pack 1.0 > > Search Path: > .GlobalEnv, package:methods, package:ctest, package:mva, package:modreg, package:nls, package:ts, > file:c:/HOME/rmh/hh/splus.library/.RData, package:grid, package:lattice, Autoloads, package:base > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel > >-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Richard M. Heiberger
2004-Feb-01 00:10 UTC
[Rd] Naming difference in cbind between S-Plus (PR#6515)
I see valid reasons and will therefore adopt the defensive coding practice: abc <- cbind(abc, d=abc$y - predict.lm(abc.lm, type="terms")[,1]) which works the same in both S-Plus and R and gives the answer I want. The result of predict.lm is not a data.frame. It is a "structure" in S-Plus and a "matrix" in R. S-Plus 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 On spelling of the name S-Plus or S-PLUS, both are correct. I normally write in LaTeX, so I normally use {\sc S-Plus}. First, from the literature, the Proprietary Notice on the copyright page of the July 2001 printed edition says {\sc S-Plus} 6 for Windows User's Guide Most of the internal uses of the word in the book are also in smallcaps {\sc S-Plus}. The outside cover does say S-PLUS. The title page says {\sc S-Plus}. Second, by personal discussion, I discussed this spelling with Tim Hesterberg about a year ago. He told me that S-Plus is an appropriate spelling. Third, by gestalt, "S-PLUS" looks like the "PLUS" is the most important part---simply because it occupies more space. "S-Plus" looks like the "S" is the most important part---because the "S" is full size and the "Plus" is typographically subsidiary. Rich