[R] Vector indices and minus sign

Tony Plate tplate at blackmesacapital.com
Fri Nov 14 20:12:38 CET 2003


At Friday 05:06 PM 11/14/2003 +0000, Patrick Burns wrote:


>Liaw, Andy wrote:
> > [material omitted...]
> >
> >I guess this can only work if "-" is treated specially in the subset
> >operators, so that, e.g., x[-"Andy"] would also work.  (This would be nice,
> >IMHO.)
> >
>I agree that  x[-c("Andy", "Pat")] would come in handy at times, but
>x[-numeric(0)] still can not work because the numbers that aren't there
>might be negative and the minus sign is to put them positive.
>
>Pat

Maybe what's needed is a new simple class that wraps vectors that can be 
used as indices, e.g.,

 > x[subomit(c("Andy", "Pat"))] # returns all elements except those named
 > x[subomit(c(1,4,9))]
 > x[subomit(numeric(0))] # returns all elements

This would require appropriate modifications to the code for "[" to detect 
when its indices were of class "subomit".

-- Tony Plate




More information about the R-help mailing list