[Rd] Strange behaviour of the [[ operator

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Sep 30 19:00:50 CEST 2006


Seth Falcon <sfalcon at fhcrc.org> writes:

> > Similar things happen in many similar circumstances.
> 
> Here's a similar thing:

Not really, no?
 
> > v <- 1:5
> > v
> [1] 1 2 3 4 5
> > v[mustBeDocumentedSomewhere=3]
> [1] 3
> 
> And this can be confusing if one thinks that subsetting is really a
> function and behaves like other R functions w.r.t. to treatment of
> named arguments:
> 
> > m <- matrix(1:4, nrow=2)
> > m
>      [,1] [,2]
> [1,]    1    3
> [2,]    2    4
> > m[j=2]
> [1] 2

Or even
> m[j=2,i=]
[1] 2 4

However, what would the argument names be in the >2-dim case? i, j are
used only in help("[") and that page is quite specific about
explaining that named matching doesn't work. 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-devel mailing list