[6501] in s-news-athena
Undesirable behavior of c()
daemon@ATHENA.MIT.EDU (Steven P. Millard)
Thu Feb 23 13:14:01 1995
Date: 23 Feb 95 12:43:15 EST
From: "Steven P. Millard" <74273.3130@compuserve.com>
To: StatSci Tech Support <support@statsci.com>
Cc: S-news <S-news@utstat.toronto.edu>
Hello there,
I'm sending this message to StatSci tech support, but I thought
the people on this mailing list would be interested. I can't recall if
the problem has already been discussed here or not.
---------------------------------------------------------------------------------
First of all, before I lodge my complaint, let me say that S-PLUS is a phenomenal
programming language, and I hope that with the increasing speed of computers and
improvements in S-PLUS memory handling I never have to program in Fortran
again. (Yes, my friends classify me as an extreme optimist.)
Now for the complaint:
I have come across an undesirable behavior of the c() function:
> dum <- 1:3
> names(dum) <- letters[1:3]
> dum
a b c
1 2 3
> c(v1 = dum["a"], v2 = dum["c"])
v1.a v2.c
1 3
> c(v1 = dum[1], v2 = dum[3])
v1.a v2.c
1 3
Now why did S-PLUS add the '.a' to 'v1' and the '.c' to 'v2'? Yes, I understand that
when I subscript dum, the 'names' attribute will be retained, but in this case I
specifically told c() that the names of the elements should be 'v1' and 'v2'.
While S-PLUS may be trying to be helpful by reminding me where v1 and v2 came from,
this is a very unexpected behavior and I don't like it. Please change it!
I realize the work-around is as follows:
> dum2 <- dum[c("a", "c")]
> names(dum2) <- c("v1", "v2")
> dum2
v1 v2
1 3
--Steve M.
(~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)
( _____________ )
( | *** | Steven P. Millard )
( | * | )
( | * * * | P robability, )
( | * * * | S tatistics & )
( | * | I nformation )
( | * | )
( | *** | 7723 44th Avenue NE )
( |___________| Seattle, WA 98115 USA )
( )
( Voice/FAX: (206) 528 - 4877 )
( E-mail: 74273,3130@CompuServe.COM )
(___________________________________________________________)