[R] x[c(1,2,1)] <- 1:3

Robin Hankin rksh at soc.soton.ac.uk
Fri Oct 24 11:18:25 CEST 2003


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




More information about the R-help mailing list