Proper subset: A proper subset S' of a set S is a subset that is strictly contained in S and so excludes S itself (note I am also excluding the empty set).
Suppose you have the following vectors in a list:
a = c(1,2)
b = c(1,3)
c = c(2,4)
d = c(1,2,3,4)
e = c(2,4,5)
f = c(1,2,3)
My aim is to keep only vectors which have no proper subset within the list, which in this example would be a, b and c. The following code is my solution,
possibilities = list(a,b,c,d,e,f)
final.list <- possibilities
for (i in possibilities) {
for (j in rev(possibilities)) {
if (all(i %in% j) & !all(j %in% i)) {
final.list <- final.list[!(final.list %in% list(j))]
} else {
final.list <- final.list
}
}
}
which gives the intended output, though I am concerned with the scalability of this approach. Does anyone have an idea for a more efficient approach? Thanks!
* Note that for my true purpose the length of the possibilities list--and its sub-vectors--can grow quite large.