[Rd] double bracket stripping names
Hervé Pagès
hpages at fhcrc.org
Wed Feb 27 01:42:13 CET 2013
Hi Patrick,
On 02/26/2013 02:30 AM, Patrick Burns wrote:
> Is it on purpose that `[[` strips the
> names when used on an atomic vector?
>
> > c(a=1, b=2)[1]
> a
> 1
> > c(a=1, b=2)[[1]]
> [1] 1
FWIW, here are a couple of other interesting facts about this:
(a) [[ is about twice faster than [ for me (64-bit Ubuntu)
on a named atomic vector.
(b) [[ raises an error if the subscript is out of bounds:
> c(a=1, b=2)[3]
<NA>
NA
> c(a=1, b=2)[[3]]
Error in c(a = 1, b = 2)[[3]] : subscript out of bounds
Can be useful in some contexts.
Cheers,
H.
>
>
> > 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
>
>
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the R-devel
mailing list