0
$\begingroup$

so let's say you have a dataset like:

prod = c(rep("A", 5), rep("B", 7), rep("C", 4))
components = c("C1", "C2", "C3", "C4", "C5",  # Product A (5)
               "C1", "C2", "C3", "C4", "C6", "C7", "C8", # Product B (7)
               "C1", "C2", "C3", "C9")   # Product C (4)
df = data.frame(Product = prod,
                Components = components)`

I want to find the maximum set of components that are in the most number of products. Then the max set of components that are in the second-most number of products, and the third and etc.

In this case, I think the result would be components "C1", "C2", and "C3" are the max set that is in the most groups (all 3 products).

A naïve solution would be to loop through all combinations of groups and compare the length of the intersection of all their component sets; however, this is not very feasible when you're dealing with over 1,000 products.

$\endgroup$
1
  • $\begingroup$ This looks like a pure programming problem, but it's unclear what "maximum set of components ... in the most number of products" might mean. Do you just want to rank components by the number of products they appear in? $\endgroup$
    – whuber
    Jun 23 at 20:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.