[R] Unexpected result of names<-
Hong Ooi
Hong.Ooi at iag.com.au
Wed Nov 16 02:01:38 CET 2005
_______________________________________________________________________________________
Note: This e-mail is subject to the disclaimer contained at the bottom of this message.
_______________________________________________________________________________________
Hi,
I came across some rather unexpected behaviour the other day with
assigning names and lists. Here's an example.
> z <- list(aaa=1, bbb=2)
> z
$aaa
[1] 1
$bbb
[1] 2
Note that z has members named "aaa" and "bbb". Now:
> names(z$a) <- "X"
> z
$aaa
[1] 1
$bbb
[1] 2
$a
X
1
I would have expected that trying to name z$a would either give an error
(because z doesn't have an element "a") or would cause z$aaa to be
modified (due to partial name matching). I didn't expect that a new
list member would be created.
I've checked that this is consistent across SPlus 2000, SPlus 7, and R
2.2 for Windows. Can someone give an explanation for why this is
happening?
--
Hong Ooi
Senior Research Analyst, IAG Limited
388 George St, Sydney NSW 2000
(02) 9292 1566
_______________________________________________________________________________________
The information transmitted in this message and its attachments (if any) is intended
only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any review,
retransmission, dissemination or other use of, or taking of any action in reliance
upon this information, by persons or entities other than the intended recipient is
prohibited.
If you have received this in error, please contact the sender and delete this e-mail
and associated material from any computer.
The intended recipient of this e-mail may only use, reproduce, disclose or distribute
the information contained in this e-mail and any attached files, with the permission
of the sender.
This message has been scanned for viruses with Symantec Scan Engine and cleared by
MailMarshal.
More information about the R-help
mailing list