[Rd] double bracket stripping names

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Feb 26 11:41:26 CET 2013


On 26/02/2013 10:30, Patrick Burns wrote:
> Is it on purpose that `[[` strips the
> names when used on an atomic vector?

Yes, and documented! It does when used on a list, so is consistent.

           ‘"[["’ can be used to select
      a single element _dropping_ ‘names’, whereas ‘"["’ keeps them,
      e.g., in ‘c(abc = 123)[1]’.



>
>  > c(a=1, b=2)[1]
> a
> 1
>  > c(a=1, b=2)[[1]]
> [1] 1
>
>
>  > sessionInfo()
> R Under development (unstable) (2013-02-11 r61902)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list