Hin-Tak Leung
2007-Jan-18 11:59 UTC
[Rd] subsetting matrix by subscript=0,x silently skips.
(e-mailing to R-bugs is intentional - the web itnerface seems to be down) > a<- cbind(c(1,2), c(3,4)) > a [,1] [,2] [1,] 1 3 [2,] 2 4 > a[cbind(c(2,2), c(2,1))] [1] 4 2 > a[cbind(c(2,3), c(2,1))] Error: subscript out of bounds > a[cbind(c(2,-1), c(2,1))] Error: negative values are not allowed in a matrix subscript > a[cbind(c(2,0), c(2,1))] [1] 4 Am somewhat surprised that 2,0 just silently skip over and doesn't throw an error like 2,0 and 2,-1 . Surely it should throw an error about subscript should be >= 1? > sessionInfo() R version 2.4.1 (2006-12-18) i686-redhat-linux-gnu locale: LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] "splines" "stats" "graphics" "grDevices" "utils" "datasets" [7] "methods" "base" other attached packages: snpMatrix survival "1.0.4" "2.30" >
The help page for "[" says: 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. Negative indices are not allowed in the index matrix. NA and zero values are allowed: rows of an index matrix containing a zero are ignored, whereas rows containing an NA produce an NA in the result. So, I think it is behaving as documented. -- Tony Plate Hin-Tak Leung wrote:> (e-mailing to R-bugs is intentional - the web itnerface seems to > be down) > > > a<- cbind(c(1,2), c(3,4)) > > a > [,1] [,2] > [1,] 1 3 > [2,] 2 4 > > > a[cbind(c(2,2), c(2,1))] > [1] 4 2 > > a[cbind(c(2,3), c(2,1))] > Error: subscript out of bounds > > a[cbind(c(2,-1), c(2,1))] > Error: negative values are not allowed in a matrix subscript > > a[cbind(c(2,0), c(2,1))] > [1] 4 > > Am somewhat surprised that 2,0 just silently skip over and doesn't > throw an error like 2,0 and 2,-1 . Surely it should throw > an error about subscript should be >= 1? > > > > > sessionInfo() > R version 2.4.1 (2006-12-18) > i686-redhat-linux-gnu > > locale: > LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C > > attached base packages: > [1] "splines" "stats" "graphics" "grDevices" "utils" "datasets" > [7] "methods" "base" > > other attached packages: > snpMatrix survival > "1.0.4" "2.30" > > > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Peter Dalgaard
2007-Jan-18 16:14 UTC
[Rd] subsetting matrix by subscript=0,x silently skips.
Hin-Tak Leung wrote:> (e-mailing to R-bugs is intentional - the web itnerface seems to > be down) >So is the mail interface... I have alerted our support people, but I didn't see the problem until I came back from teaching, so they may not get it fixed before tomorrow. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907