Hi everyone. look at this: x <- 1:4 x[c(1,2,1)] <- (1:3) print(x[1]) I get 3, but isn't NA more appropriate? [1 would be as sensible]. FWIW, the equivalent Fortran 95 statement is flagged as an error. R-intro, section 2.7, says that in such cases the assignment is carried out "in order" which might support getting 3. To my way of thinking, the concept of "in order" seems to violate the usual strategy of considering vectors as whole entities---because in this case we have to specify whether the assignment starts at c(1,2,1)[1] and proceeds to c(1,2,1)[3], or starts at c(1,2,1)[3] and proceeds to c(1,2,1)[1]. And the results are different! What is the R position on this? rksh
?order descending in means "order" assume always you Do> -----Original Message----- > From: Robin Hankin [mailto:rksh at soc.soton.ac.uk] > Sent: 24 October 2003 10:18 > To: r-help at stat.math.ethz.ch > Subject: [R] x[c(1,2,1)] <- 1:3 > > > Security Warning: > If you are not sure an attachment is safe to open please contact > Andy on x234. There are 0 attachments with this message. > ________________________________________________________________ > > Hi everyone. > > look at this: > > x <- 1:4 > x[c(1,2,1)] <- (1:3) > print(x[1]) > > I get 3, but isn't NA more appropriate? [1 would be as sensible]. > FWIW, the equivalent Fortran 95 statement is flagged as an error. > R-intro, section 2.7, says that in such cases the assignment is > carried out "in order" which might support getting 3. > > To my way of thinking, the concept of "in order" seems to violate the > usual strategy of considering vectors as whole entities---because in > this case we have to specify whether the assignment starts at > c(1,2,1)[1] and proceeds to c(1,2,1)[3], or starts at c(1,2,1)[3] and > proceeds to c(1,2,1)[1]. And the results are different! > > > What is the R position on this? > > > rksh > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
On Fri, 24 Oct 2003, Robin Hankin wrote:> Hi everyone. > > look at this: > > x <- 1:4 > x[c(1,2,1)] <- (1:3) > print(x[1]) > > I get 3, but isn't NA more appropriate? [1 would be as sensible]. > FWIW, the equivalent Fortran 95 statement is flagged as an error. > R-intro, section 2.7, says that in such cases the assignment is > carried out "in order" which might support getting 3. > > To my way of thinking, the concept of "in order" seems to violate the > usual strategy of considering vectors as whole entities---because in > this case we have to specify whether the assignment starts at > c(1,2,1)[1] and proceeds to c(1,2,1)[3], or starts at c(1,2,1)[3] and > proceeds to c(1,2,1)[1]. And the results are different! > > > What is the R position on this?That this is correct and works as documented! It is occasionally useful. R implements the S language, not Fortran 95, so consult the S references please. -- Brian D. Ripley, ripley at 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