[Solved] regex for replacement of non-numeric character INSIDE parenthesis within a string in dyplr workflow

TarJae Asks: regex for replacement of non-numeric character INSIDE parenthesis within a string in dyplr workflow
My question is somehow related to an already answered question Need to extract individual characters from a string column using R.

I try to solve this question with my knowledge and need to know how to remove non numeric characters in parenthesis within a string: `

This is the dataframe with column x:

Code:
  team     linescore     ondate                                     x
1  NYM     010000000 2020-08-01             0, 1, 0, 0, 0, 0, 0, 0, 0
2  NYM (10)1140006x) 2020-08-02 (, 1, 0, ), 1, 1, 4, 0, 0, 0, 6, x, )
3  BOS     002200010 2020-08-13             0, 0, 2, 2, 0, 0, 0, 1, 0
4  NYM  00000(11)01x 2020-08-15    0, 0, 0, 0, 0, (, 1, 1, ), 0, 1, x
5  BOS        311200 2020-08-20                      3, 1, 1, 2, 0, 0

Code:
structure(list(team = c("NYM", "NYM", "BOS", "NYM", "BOS"), linescore = c("010000000", 
"(10)1140006x)", "002200010", "00000(11)01x", "311200"), ondate = structure(c(18475, 
18476, 18487, 18489, 18494), class = "Date"), x = list(c("0", 
"1", "0", "0", "0", "0", "0", "0", "0"), c("(", "1", "0", ")", 
"1", "1", "4", "0", "0", "0", "6", "x", ")"), c("0", "0", "2", 
"2", "0", "0", "0", "1", "0"), c("0", "0", "0", "0", "0", "(", 
"1", "1", ")", "0", "1", "x"), c("3", "1", "1", "2", "0", "0"
))), class = "data.frame", row.names = c(NA, -5L))

Desired Output:

Code:
  team     linescore     ondate                             x
1  NYM     010000000 2020-08-01     0, 1, 0, 0, 0, 0, 0, 0, 0
2  NYM (10)1140006x) 2020-08-02 10, 1, 1, 4, 0, 0, 0, 6, x, )
3  BOS     002200010 2020-08-13     0, 0, 2, 2, 0, 0, 0, 1, 0
4  NYM  00000(11)01x 2020-08-15    0, 0, 0, 0, 0, 11, 0, 1, x
5  BOS        311200 2020-08-20              3, 1, 1, 2, 0, 0

How can I change (, 1, 0, ) to 10 and (, 1, 1, ) to 11 and leave the rest as is.

Some help I already got so far:

  1. regex for replacement of specific character outside parenthesis only thanks AnilGoyal
  2. gsub("\D+", "", str1) thanks to akrun
  3. gsub("[(,) ]", "", "(, 1, 0, )") thanks to Anoushirvan

Thanks!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.