[Rd] subsetting matrix by subscript=0,x silently skips.
tplate at blackmesacapital.com
Thu Jan 18 19:03:45 CET 2007
Hin-Tak Leung wrote:
> (I have taken off r-bug@, as multiple e-mails hitting r-bug@ probably
> will result in multiple bug reports, knowing most mail server will
> Tony Plate wrote:
>> 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.
> Hmm, fair enough. I guess the NA one make sense (In R as a rule,
> NA in, NA out), but I am not sure I understand or agree with
> the rationale of silently ignoring (0,x) and (x,0)'s. Any reason for that?
AFAIK, the reason is to make the behavior analogous to how regular
indices are treated, e.g.:
> x <- array(1:6, dim=2:3)
(i.e., 0's in indices are omitted)
-- 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))]
>>>  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))]
>>>  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)
>>> attached base packages:
>>>  "splines" "stats" "graphics" "grDevices" "utils"
>>>  "methods" "base"
>>> other attached packages:
>>> snpMatrix survival
>>> "1.0.4" "2.30"
>>> R-devel at r-project.org mailing list
More information about the R-devel