I have some rows, some have parenthesis and some don't. Like ABC(DEF)
and ABC
. I want to extract info from parenthesis:
- ABC(DEF) -> DEF
- ABC -> NA
I wrote
gsub(".*\\((.*)\\).*", "\\1",X).
It works good for ABC(DEF), but output "ABC" when there is not parenthesis.