So I have two data.tables.
size_categories = data.table(category = c("S", "M", "L"), size_min = c(0, 10, 25),
size_max = c(10, 25, Inf), bin = c("blue", "red", "green"))
products = data.table(object_id = 1:10, size = seq(1, 37, 4))
I want to merge the tables such that each row of the product table is assigned a bin and size category based on its size.
The ham-fisted way I know would be to assign assign a category to each row on products and then merging
products[size >= 0 & size < 10, category := "S"]
products[size >= 10 & size < 25, category := "M"]
products[size >= 25, category := "L"]
merge(products, size_categories)
Of course this is not flexible at all and I would have to rewrite it if size_categories changed.
I am open to using other packages, but would prefer a solution just using data.table.
Thanks!