Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does R have 'dict' as in python or 'map' as in c++ do?

Tags:

r

I am new to R programming. After checking some tutorial I picked up most things I needed, but one thing is still missing: the data structure map.

Does everybody know if R has dict? In which I can store (key, value) pairs?

Thanks!!

like image 555
dgg32 Avatar asked Jan 24 '11 22:01

dgg32


1 Answers

Since array/vector elements can be named, you get some of the properties of a map/dictionary builtin.

x <- c(apple = 1, banana = 99, "oranges and lemons" = 33)
x["apple"]
x[c("bananas", "oranges and lemons")]
x[x == 99]

(If your values are of different types, then you need to use a list instead of a vector.)

like image 198
Richie Cotton Avatar answered Oct 15 '22 22:10

Richie Cotton