Re: [R] beginner Q: hashtable or dictionary?

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Tue 31 Jan 2006 - 01:55:59 EST

> On 1/29/06, context grey <mobygeek@yahoo.com> wrote:

>>
>> Hi,
>>
>> Is there something like a hashtable or (python)
>> dictionary in R/Splus?

On 29 Jan 2006, jholtman@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]] <- 2
    names(h) <- rep("foo", 2)
    h

      $foo
      [1] 1
      
      $foo
      [1] 2
    
    h[["foo"]]
      [1] 1

'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.

+ seth



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jan 31 02:14:12 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:15 EST