I read the answers about creating dictionary in r.
equivalent of a python dict in R
Is there a dictionary functionality in R
And I have a question: how could I use this in a large dataset? Data structure is like this:
dput of a subsample is:
structure(list(...1 = c("category 1", NA, NA, NA, "total", "category 2",
NA, NA, NA, "total"), Items = c("product 1", "product 2", "product 3",
"product 4", NA, "product 1", "product 2", "product 3", "product 4",
NA), price = c(1, 2, 3, 4, 10, 3, 4, 5, 6, 18)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
And I want the result be like:
categoryx: {prodcut1:1, product2:2, product3:3....}
What could I do if the there are 1000 categories and the number of products for each category is different? The answers in above two links, values of each key should be added manually, I don't how to use it for a large dataset.
Or is there other method (except create dictionaries) that could let me extract information of each category easily?
Could someone give ideas about this question? Thanks.
Is it possible to have a result like a dictionary(or list) of dictionaries in python?
such as dict={category1: {prodcut1:1, product2:2, product3:3....}, category2: {prodcut1:3, product2:4, product3:5....} }
So I could know categories's index and use the index to extract information from dict, and maybe it is like such a dataframe:
item price
categoryx product1 2
product2 3
so I could do operations for specific category?