I would like to obtain the indices of all elements of a character vector that contain " + ".
- c("A + B", "C") should output 1.
- c("A + B", "C + D") should output c(1, 2).
- c("A", "B") should output integer(0).
I have tried using grep(pattern = " + ", x), but this returns integer(0) regardless of what x is. I have also tried using grep(pattern = "+", x), but this returns seq_along(x) no matter what x is. I suspect that this has to do with + being a special character, but I'm not sure how to fix this.