[R] names in R list's
b.rowlingson at lancaster.ac.uk
Mon Sep 7 15:25:45 CEST 2015
On Mon, Sep 7, 2015 at 11:34 AM, Witold E Wolski <wewolski at gmail.com> wrote:
> What is the access time for R lists given a name of list element, is it
> linear, log, or constant?
Try it and see?
> Than what are to rules for names in R-lists
> That reusing names is possible makes me wonder.
> tmp <- as.list(c(1,2,3,4))
> names(tmp) = c("a","a","b","b")
> What I am looking for is a standard R data structure which will allow me
> for fast and name lookup.
Depends what you mean by "standard"?
There's a `hash` package that implements what are variously known as
hash tables or associative arrays (in perl) and dictionaries (in
<hash> containing 1 key-value pair(s).
a : 99
There's no ordering so numeric indexing fails:
Error in get(k, x) : invalid first argument
Error in z[] : wrong arguments for subsetting an environment
<hash> containing 2 key-value pair(s).
a : 99
b : 123
and the keys are unique, even if you try:
> z=hash(c("a","b","b","c"), 1:4)
<hash> containing 3 key-value pair(s).
a : 1
b : 3
c : 4
I guess the lookup uses the usual fast hash lookup algorithms, but
you'd have to check the docs and source for details.
More information about the R-help