[R] subset, once more

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jul 8 21:16:06 CEST 2002

"RenE J.V. Bertin" <rjvbertin at hotmail.com> writes:

> New to R, I had the bad idea to send a bug report about '[' not
> knowing it had a drop= argument. Now, I wonder about the absence of
> this argument in subset...
> In both availabe methods (see below), there is a ... argument, but
> this argument is not used in either. Rather, subset.data.frame
> explitictly passes drop=F in 1 instance.
> Before I start patching (for my own use): what is the reason for this?

"..." is generally used in methods, in case someone defines a method
with further arguments for a subclass and wants to use NextMethod().
It's not a bug that no existing method actually uses it.

There's no particular reason not to pass ... on to the indexing in
subset.default, except that the author didn't think about it. I don't
think the default method gets used much, but it might be useful to 
change it to

function (x, subset, ...) 
x[subset & !is.na(subset),...]

(This would likely change the semantics for the case where x is a
matrix or array. Possibly for the better.)

In subset.data.frame, the drop=F ensures that you get a data frame as
the result even if only a single column is selected (or there was only
a single column to begin with). I think this is as it should be. If
you look closer, you'll see that the drop=F is actually applied in
*all* instances and that all four arguments to [.data.frame are passed
explicitly so there's no point in passing ... there.
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list