Beginner all %in% question

If I'm checking if "B", "BB", and "BBB" are all present (in any order) in a vector 'symbols', shouldn't I write my condition as all(c("B", "BB", "BBB") %in% symbols) instead of all(symbols %in% c("B", "BB", "BBB"))? or does it not matter.

The order matters in the general case. You are checking if the elements of the vector on the left side of %in% are members of the vector on the right. The vector on the right may have extra elements without affecting the result.

symbols <- c("A","B","C","D")
all(c("B","C") %in% symbols)
[1] TRUE
all(symbols %in% c("B","C"))
[1] FALSE
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.