[R] strange matrix behaviour: is there a matrix with one row?
François Pinard
pinard at iro.umontreal.ca
Fri Apr 7 15:27:53 CEST 2006
[ryszard.czerminski at novartis.com]
>> y <- matrix(1:8, ncol=2)
>> is.matrix(y[-c(1,2),])
>[1] TRUE
>> is.matrix(y[-c(1,2,3),])
>[1] FALSE
>> is.matrix(y[-c(1,2,3,4),])
>[1] TRUE
>It seems like an inconsistent behaviour:
>- with 2 or more rows we have a matrix
>- with 1 row we do not have a matrix and
>- with 0 rows we have a matrix again
?'[' explains it. Using your example:
> is.matrix(y[-c(1, 2), , drop=FALSE])
[1] TRUE
> is.matrix(y[-c(1, 2, 3), , drop=FALSE])
[1] TRUE
> is.matrix(y[-c(1, 2, 3, 4), , drop=FALSE])
[1] TRUE
--
François Pinard http://pinard.progiciels-bpi.ca
More information about the R-help
mailing list