In R I was wondering if I could have a dictionary (in a sense like python) where I have a pair (i, j)
as the key with a corresponding integer value. I have not
Here's how you'd do this in a data.table
, which will be fast and easily extendable:
library(data.table)
d = data.table(i = 1, j = 2:5, value = c(1,3,4,3), key = c("i", "j"))
# access the i=1,j=3 value
d[J(1, 3)][, value]
# change that value
d[J(1, 3), value := 12]
# do some vector assignment (you should stop thinking loops, and start thinking vectors)
d[, value := i * j]
etc.