I have the following vector for an example.
isotopes <- c("6Li", "7Li", "7LiH", "10B", "11B", "11BH")
I want to remove the strings "7LiH"
and "11BH"
from the vector. These values have two capital letters and so I am trying to figure out how to use grep
to remove those values or just index out the other strings in the vector. How can I do this?
You can simply grep for elements that contain 2 or more capital letters and invert the match:
grep('[A-Z].*[A-Z]', isotopes, value=TRUE, invert=TRUE)
The regex matches a string that contains an uppercase letter, then probably something else and then one more uppercase letter (not necessary at the beginning or end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With