I saw this post comparing the performance of different name lookup operation in R http://broadcast.oreilly.com/2010/03/lookup-performance-in-r.html
Here is the result for name lookup performance using single bracket '[' on a vector. 1st row = vector length, 2dn row = time.
arrays, first element, by label, single bracket:
1024 2048 4096 8192 16384 32768
0.268 0.282 0.588 1.439 2.728 5.397
arrays, last element, by label, single bracket:
1024 2048 4096 8192 16384 32768
0.173 0.278 0.582 1.517 2.713 5.266
Does any body know why lookup time for the first and last element are the same for single bracket on named vector? Why lookup time for the first element is linear? In the post,
"When you use single-bracket notation, R tried to match all elements with a given label, including fuzzy matches. That means that R scans all the element in the array when you use single bracket notation."
However, this does not make sense as from my experiment if there is duplicated names in a vector, '[' with one label returns only the first one, not all. If the name cannot be found exactly, it returns NA.
> x = c('a'=1, 'b'=2, 'c' = 3, 'b'=4)
> x['b']
b
2
> x2 = c('ba' = 1, 'a'=2)
> x2['b']
<NA>
NA
```