[Rd] subset() wish: allow "select" for non-dataframes

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 26 Sep 2000 21:52:47 +0200


{Mainly to the author of the subset() function,
 but RFC to all "R-develers": }

Wouldn't it be worth redefining  subset.default() such
that `anything reasonable' would allow a select argument?

Currently, only subset.data.frame() allows a select argument,
and hence we can have

  > (x <- c(a=1, b=3, d= 7:10))
   a  b d1 d2 d3 d4 
   1  3  7  8  9 10 

  > subset(as.data.frame(rbind(x)), select = -(d2:d3))
    a b d1 d4
  x 1 3  7 10

{and ``subset(as.data.frame(rbind(x)))'' might already be a sensible
 definition for  subset.default  at least 
 if(!missing(select) && !is.null(names(x))); 
 and similarly for matrices.
}

---

Using  ranges and "-" in indices for names instead of just integers 
is a feature that I have been missing for a long time.
It would allow much more expressive code in some situations.


2nd thought: 
      One could even start thinking if we should n't even enhance
      "[" and "[[" instead of just  subset()...

I agree that one might not like things like   x[- d1] that are
undefined when not part of the index, but then 
"i , j" is also not really defined when not inside "[ .. ]" ...

--
[Evening musings;  maybe I'm too close to dream already...]

Martin


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._