This discussion reminds me of another disanalogy in vector/list
double/single-bracket numeric/named indexing.
First, here's what happens when the item is present. The behavior is
consistent (or at least makes sense) across the different ways of getting
the value from vectors and lists:
# Named in
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-b
> Yes, as Brian said. And this makes sense: the names are a property of the
> container, not a property of the contents. Using single brackets creates a
> new container with a subset of the elements. Using double brackets extracts
> an element.
>
> The fact that there's no way to hold a number
On 13-02-26 5: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
Yes, as Brian said. And this makes sense: the names are a property of
the container, not a property of the contents. Using
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,
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
> 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=