[R] beginner Q: hashtable or dictionary?
sfalcon at fhcrc.org
Mon Jan 30 15:55:59 CET 2006
> On 1/29/06, context grey <mobygeek at yahoo.com> wrote:
>> Is there something like a hashtable or (python)
>> dictionary in R/Splus?
On 29 Jan 2006, jholtman at gmail.com wrote:
> use a 'list':
Most of the time, a list will be what you want, but it has some
important differences from a Python dictionary. In particular, one
can end up with duplicate keys. Here is an example:
h <- list()
h[["foo"]] <- 1
h[] <- 2
names(h) <- rep("foo", 2)
'environments' may be what you are looking for, see help for new.env().
h <- new.env(hash=TRUE)
An important thing to keep in mind with environments, however, is that
they are an exception to the pass by value semantics of the language.
Environments are not copied when passed as function args. This has
its uses, but can be confusing.
More information about the R-help