I have a basic table that looks like this:
df = data.table(id1 = c(22,23,45,78,96,45,21,58), id2 = c(24,84,64,82,84,53,54,85))
I'm trying to lookup information in a nested json. A basic request that works with my current json file is the following one :
json$32
$cat1$cat291
, which returns a value.
"32" and "91" are the Ids, and "cat1" and "cat2" are just nested tables (or whatever it is called X) ).
Cat1 and Cat2 will never change, but I do need to replace the Ids with the ones in my df table, to create a new variable in df (which I will call "val"), with the values from the json.
So here is what I tried to do :
id1 = as.character(df$id1)
id2 = as.character(df$id2)
Now, I want to automatically find the values of all the combinations of id1 and id2 in my df :
df$val = json$id1$cat1$cat2$id2
Unforntunately, it yields the following error :
Warning message :
In ' [<-.data.table'(x, j = name, value = value) :
Adding new column 'val' then assigning to NULL (deleting it).
I'm sure there is a very simple way to do this, but I could not find an answer :X ...
Thank you very much for your help :), JB