[R] strange matrix behaviour: is there a matrix with one row?
dimitris.rizopoulos at med.kuleuven.be
Fri Apr 7 15:30:21 CEST 2006
this is documented: check ?"[". You need to specify drop = FALSE,
is.matrix(y[-c(1,2,3), , drop = FALSE])
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
----- Original Message -----
From: <ryszard.czerminski at novartis.com>
To: "Gabor Grothendieck" <ggrothendieck at gmail.com>
Cc: "Brian Quinif" <bquinif at gmail.com>; <r-help at stat.math.ethz.ch>;
<r-help-bounces at stat.math.ethz.ch>
Sent: Friday, April 07, 2006 3:16 PM
Subject: [R] strange matrix behaviour: is there a matrix with one row?
> Consider this:
>> y <- matrix(1:8, ncol=2)
>  TRUE
>  FALSE
>  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
> I just stumbled on this behaviour, because I had a problem
> with my program in which I have assumed that matrix with
> some rows removed is still a matrix, which seems to be mostly
> true, but it is not true if only one row is left.
> Comments? Suggestions?
> How to work around this problem - without to many "if" statements?
> Best regards,
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide!
More information about the R-help