Why associative array of R is called list and not map/dictionary [closed] Why associative array of R is called list and not map/dictionary [closed] r r

Why associative array of R is called list and not map/dictionary [closed]


S has a longer history than do either Java or Python. The terminology derives from LisP one of the first high level languages.

Furthermore, you can create what some people might call an associative array by using a named atomic vector:

 vec <- c(a=1,b=2,c=3) vec["b"] #b  #2 

There are two sort of vectors: "recursive" and "atomic". Lists are of the first sort. Both can be indexed by "name" if there are keys assigned to the elements. However the term "name" in R strictly refers to symbols that exist in an environment that have object values. See ?as.name. In R "names" or "symbols" are language objects that in code are not quoted, whereas character values are used to assign or extract value from data objects by keys.


A "Map" is a chart of the world. To find things on a map you have to scan in two dimensions. This is O(n^2). A "Dictionary" is a book of words in alphabetical order. To find a word in a dictionary you have to do a binary search. This is O(log n) performance.

So neither of those words, to me, accurately portray the structure nor the performance of an associative array...

Mathematically speaking an associative array is simply a function over a discrete range. So they should just be called functions. Double-square brackets are just a syntactic annoyance. Why can't we do:

z = list()z("foo") = c(1,2,3)print(z("foo")) # prints 1 2 3print(z("bar")) # errors
  • because R isn't like that.