salking at verizon.net
2006-Oct-18 23:29 UTC
[Rd] Error: subscript out of bounds (PR#9305)
Full_Name: Steven King Version: 1.16 OS: OSX vesion 10.4.8 Submission from: (NULL) (71.126.161.149) Setting a matrix is a function - the failure occurs only on 2 X 2 matrices. x<-matrix(1:4,nrow=2)> x[,1] [,2] [1,] 1 3 [2,] 2 4> x[x]<-2Error: subscript out of bounds
See ?"[" and note in particular "A third form of indexing is via a numeric matrix with the one column for each dimension: each row of the index matrix then selects a single element of the array, and the result is a vector." Thus the result in this case should be a vector with element 1,3 as its first component and element 2,4 as its second. Of course since x is 2x2 neither of these exist. Thus its behaving correctly. On 10/18/06, salking at verizon.net <salking at verizon.net> wrote:> Full_Name: Steven King > Version: 1.16 > OS: OSX vesion 10.4.8 > Submission from: (NULL) (71.126.161.149) > > > > Setting a matrix is a function - the failure occurs only on 2 X 2 matrices. > > x<-matrix(1:4,nrow=2) > > x > [,1] [,2] > [1,] 1 3 > [2,] 2 4 > > x[x]<-2 > Error: subscript out of bounds > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
ripley at stats.ox.ac.uk
2006-Oct-19 06:20 UTC
[Rd] Error: subscript out of bounds (PR#9305)
Why do you consider this to be a bug: you are using matrix indexing, and there is no element c(1,3) of x? This form of indexing is covered in 'An Introduction to R'. On Thu, 19 Oct 2006, salking at verizon.net wrote:> Full_Name: Steven King > Version: 1.16There is no such version of R.> OS: OSX vesion 10.4.8 > Submission from: (NULL) (71.126.161.149) > > > > Setting a matrix is a function - the failure occurs only on 2 X 2 matrices. > > x<-matrix(1:4,nrow=2) >> x > [,1] [,2] > [1,] 1 3 > [2,] 2 4 >> x[x]<-2 > Error: subscript out of bounds-- 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