[R] omitting integer(0) rows from data frame

S Ellison S.Ellison at lgcgroup.com
Wed Oct 30 15:02:32 CET 2013

> >  dat[- integer(0), ]
> > .... unexpectedly omits ALL rows
> >
> > It would be less surprising if there were no rows omitted in the (B) case.

I tried this on two experienced R users here and their first thought* was, interestingly, as Jack indicated; that -integer(0) should drop nothing.

But Gerrit is correct; -integer(0) still evaluates to a zero length vector, not a negative, and asking for a zero-length set of rows is equivalent to asking for no rows.

Steve E

*Second thought, actually; their first thought was 'why would you do that?'. 
To be fair we did note that dropping according to an empty 'which' criterion or an unmatched grep() would do this. The 'obvious' fix would presumably be not to wrap the selection in which() at all (eg use 1:5 == 6 directly and not which(1:5 == 6) ), to use regexpr(...)>0 instead of grep etc. 

This email and any attachments are confidential. Any use...{{dropped:8}}

More information about the R-help mailing list