Matrix indexing seems to give rather "variable" results when zeros or
negative values are included among the indices (in terms of both error
messages and in terms of the number of returned values when there is no
error message).
Is this the intended behavior?
I couldn't see any comments about zeros or negative values in matrix indices in either ?"[" or Section 3.4.2 "Indexing matrices and arrays" of the "R Language Definition" (Version 2.0.1), or in Section 5.3 "Index arrays" of "An Introduction to R" (Version 2.1.0).
(It looks like the special treatment of zeros and negative indices is being applied to the vector indices after they are derived by standard indexing arithmetic from the matrix indices -- so zeros and negative values in the matrix indices have no special meaning. There does seem to be some range checking, but it's not consistent -- sometimes index values that are out of range get through.)
> x <- matrix(1:6,ncol=2)
> dim(x)
[1] 3 2
> x
[,1] [,2]
[1,] 1 4 [2,] 2 5 [3,] 3 6
> version
_
platform i386-pc-mingw32
arch i386 os mingw32
(I see the same behavior in R 2.1.0 beta of 2005/04/04)
PS: FWIW, S-PLUS 6.2 does something more like one would get when using each row of the index matrix as arguments to a call to "[", except that negative values are not allowed at all (any zero value in a row causes that row to be omitted from the result).
This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:03 GMT