Take the 2-minute tour ×

I want to store an object with a number vector as key in some data structure, such that I can later retrieve that object when I supply the data structure with an identical vector. How can I do that?

All vectors have the same number of elements. The number of objects that will be stored is low (<20).

Something like:

hash[c(1,2,4)] <- myObject
share|improve this question
Andreas, I have found that when I can't provide a reproducible example (a how to question) it's helpful to provide a before and after data set of what you're after. Here's an example of where I provided a sample input and output: stackoverflow.com/questions/12876820/… –  Tyler Rinker Nov 18 '12 at 1:22
add comment

1 Answer

up vote 2 down vote accepted

You could use a list and turn your vector key into a unique character key, using paste for example:

hash <- list()
hash[[paste(c(1,2,4), collapse = '.')]] <- 1:10
# $`1.2.4`

Same idea for retrieving the object:

share|improve this answer
add comment

Your Answer


