Skip to content

Dictionaries with integer indices

1 message · Ross Boylan

#
Some past threads have pointed out that lists can be used as
dictionaries storing data with an associated key (environments do this
too).

I have the seemingly simpler case with integer values for the
indices--however, the integers are not necessarily contiguous low
numbers.  My concern is that if id is 3000 then
d <- list()
d[[id]] <- some data

and later retrieval with
d[[id]]
is going to be wasteful (e.g., produce something with 3000 elements).

I could turn id into a string, but that seems pretty indirect.

Is there any problem with the naive scheme outlined above?  If so,
what's a good way around it?