r - Split a string by a plus sign (+) character -


i have string in data frame as: "(1)+(2)"

i want split delimiter "+" such 1 element (1) , other (2), hence preserving parentheses. used strsplit not preserve parenthesis.

use

strsplit("(1)+(2)", "\\+") 

or

strsplit("(1)+(2)", "+", fixed = true) 

the idea of using strsplit("(1)+(2)", "+") doesn't work since unless specified otherwise, split argument regular expression, , + character special in regex. other characters need care

  • ?
  • *
  • .
  • ^
  • $
  • \
  • |
  • { }
  • [ ]
  • ( )

Comments