I am a bit lost about how to optimize for loops in R.
I have a set such that element i belongs to the set iff contains[[i]] == 1
. I want to check whether sets of indices are included in this set. Currently I have the following code. Can it be written more efficiently?
contains = c(1, 0, 0, 1, 0, 1, 1, 0)
indices = c(4, 5) # not ok
# indices = c(4, 6) # ok
ok <- TRUE
for (index in indices) {
if (contains[[index]] == 0) {
ok <- FALSE
break
}
}
if (ok) {
print("ok")
} else {
print("not ok")
}