Can I use a list as a hash in R? If so, why is it so slow?

前端 未结 7 802
遇见更好的自我
遇见更好的自我 2020-11-29 23:43

Before using R, I used quite a bit of Perl. In Perl, I would often use hashes, and lookups of hashes are generally regarded as fast in Perl.

For example, the followi

7条回答
  •  不知归路
    2020-11-30 00:20

    But an environment cannot contain another environment (quoted from Vince's answer).

    Maybe it was that way some time ago (I don't know) but this information seems not to be accurate anymore:

    > d <- new.env()
    > d$x <- new.env()
    > d$x$y = 20
    > d$x$y
    [1] 20
    

    So environments make a pretty capable map/dict now. Maybe you will miss the '[' operator, use the hash package in that case.

    This note taken from the hash package documentation may also be of interest:

    R is slowly moving toward a native implementation of hashes using enviroments, (cf. Extract. Access to environments using $ and [[ has been available for some time and recently objects can inherit from environments, etc. But many features that make hashes/dictionaries great are still lacking, such as the slice operation, [.

提交回复
热议问题