[R] behaviour of rows and colomns suppression in a matrix

Olivier ETERRADOSSI olivier.eterradossi at mines-ales.fr
Thu Mar 13 17:06:33 CET 2014


Yes, that's usually what I'm doing...
Here I didn't guess that the answer was in "[" !
I already noticed that it's sometimes easier to locate something very
technical or statistically smart than obvious things (because we think we
know, or think we have already read 10 times the basics...)  ;-)
O.

-----Message d'origine-----
De : Sarah Goslee [mailto:sarah.goslee at gmail.com]
Envoyé : jeudi 13 mars 2014 16:59
À : Olivier ETERRADOSSI
Cc : r-help
Objet : Re: [R] behaviour of rows and colomns suppression in a matrix

On Thu, Mar 13, 2014 at 11:51 AM, Olivier ETERRADOSSI
<olivier.eterradossi at mines-ales.fr> wrote:
> Thank you Sarah,
>
> But no, I was not expecting this. For me integer(0) is not 0.
> That's why I finally tested length(unused.rows), which is 0 when
> unused.rows is integer(0).

Also from

?"["

i, j, ...: indices specifying elements to extract or replace.  Indices
          are 'numeric' or 'character' vectors or empty (missing) or
          'NULL'.  Numeric values are coerced to integer as by
          'as.integer' (and hence truncated towards zero).  Character
          vectors will be matched to the 'names' of the object (or for
          matrices/arrays, the 'dimnames'): see 'Character indices'
          below for further details.

So yes, in this case 0 is treated as integer(0).

When you have problems that seem odd to you, carefully reading the
relevant help is always a good place to start.

Sarah




More information about the R-help mailing list