Reputation: 105
I am trying to extract the names of the countries which don't start with either "C" or "B" from this vector.
vec <- c("Colombia", "Chile", "Brazil", "Ecuador", "Peru", "Mexico")
This works for C or B only:
vec[substring(vec,1,1) != 'C']
I am trying to combine both cases but this doesn't work
vec[(substring(vec,1,1) != 'C') | (substring(vec,1,1) != 'P')]
How can I combine both conditions in just one statement?
Upvotes: 0
Views: 46
Reputation: 6264
Isn't this what you are looking for?
vec[!substring(vec, 1, 1) %in% c("B", "C")]
Upvotes: 2