[R] language inconsistency puzzle (in the tradition of Bill V enables (Hi Bill) puzzle "what is x")
Huntsinger, Reid
reid_huntsinger at merck.com
Thu Nov 7 23:27:21 CET 2002
R allows you to dynamically extend a vector by assigning past the end. So if
a has length 10, then assigning to a[11] creates also a[11] with value
a2[11] NA. So a is now length 11, while a2 is still length 10. So the
occurrence of a[11] has a different meaning on the assigned-to side than on
the assigned-from side. E.g.
>a <- rep(1,10)
>b <- 11
>a2 <- a
>a[b] <- a2[b]
>a
[1] 1 1 1 1 1 1 1 1 1 1 NA
>a2
[1] 1 1 1 1 1 1 1 1 1 1
This doesn't seem inconsistent to me; unavoidable yes, given that you want
vectors to be dynamically extendible. Have I missed something?
Reid Huntsinger
-----Original Message-----
From: oehl_list at gmx.de [mailto:oehl_list at gmx.de]
Sent: Thursday, November 07, 2002 2:11 PM
To: r-help at stat.math.ethz.ch
Subject: [R] language inconsistency puzzle (in the tradition of Bill
Venables (Hi Bill) puzzle "what is x")
> # let's say we have two vectors a and b
> # lets make a copy of a
>
> a2 <- a
>
> # not surprisingly
> identical(a[b], a2[b])
[1] TRUE
>
> # now assigning same to same
> a[b] <- a2[b]
>
> # and SURPRISE
> identical(a, a2)
[1] FALSE
>
WHAT IS a AND b ?
Hint: this "works" under 1.5.1 and 1.6.1.
However, the final value of a will differ between 1.5.1 and 1.6.1 under
certain circumstances. Explain why it is both, DOUBLY INCONSISTENT AND
UNAVOIDABLE.
BTW, the prototype does the same.
The serious side of this: I think the situation deserves at least a WARNING.
Best
Jens Oehlschlägel
--
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.
==============================================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list