-2

Not sure if someone could help me with this problem.

I have 5 lists of values of different lengths. Note: Same value can be presence in different lists.

Does anyone know how to get the combination of 3 lists that will provide more total unique values?

Thanks in advance, Miguel

Miguel
  • 1
  • 1
    Hi, please read [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Your question is quite ambiguous. – heds1 Jul 04 '19 at 00:55

1 Answers1

0

I do not really have an answer to your question, which seems to be more of a combinatorics question than programming. My sense is that if you want an exact solution you will have to try all the possible combinations of subsets of 3 lists out of 5 (there are 10 of them). One thing to remember if you go that way is that if you want the number of unique elements of the concatenation of 3 lists you do not have necessarily to do length(unique(c(l1,l2,l3)) which I imagine could be inefficient if you have very long lists. You can use the formula for the size of the intersection of 3 sets, which you can find for example at https://math.stackexchange.com/questions/669249/probability-of-the-union-of-3-events . This will require you only to compute the length of all the possible intersections of the lists. it could be a completely academic exercise: as I said, I am not offering an answer but if you are not familiar with that formula it is worth reading it, since it is relevant to the problem of finding the size of a set.

FGirosi
  • 106
  • 5