I have the following character vector of numeric values.
X0 <- c("288", "74.00 [67.75, 80.00]", "196 (68.1)", "64.50 [57.00, 72.00]",
"1.90 [1.80, 2.00]", "27.65 [25.37, 30.63]", "138.00 [125.00, 152.00]",
"74.00 [67.50, 81.00]", "29 (10.2)", "2.84 [2.54, 3.20]", "18.00 [14.00, 23.00]",
"1.26 [1.07, 1.47]", "0.65 [0.58, 0.75]", "2.20 [2.00, 2.36]",
"3.80 [3.14, 4.36]", "21.80 [19.20, 25.00]", "43.89 [37.56, 50.00]",
"65.00 [60.00, 65.00]", "274 (95.1)", "253 (87.8)", "", "59 (20.5)",
"189 (65.6)", "40 (13.9)", "", "8 (21.6)", "6 (16.2)", "21 (56.8)",
"2 ( 5.4)", "851.50 [492.00, 1426.00]", "601.50 [337.75, 947.75]",
"447.50 [261.25, 740.50]", "226.50 [130.00, 353.25]", "43 (14.9)",
"4.50 [0.00, 30.25]", "11 ( 8.9)", "39 (31.7)", "3.38 [1.90, 5.22]"
I need to replace all decimal numbers with rounded values to 1 decimal places.
I tried the this:
str_replace(X0, "[0-9]{1,}(\\.)[0-9]{1,}", as.character(round(as.numeric("\\0"),1)))
and a couple of other variations of the following, but it only produces results with NA.
How can I replace these values as characters? This is unfortunately how the data comes to me. I need to replace these values in place. I can't simply convert each element to numeric since there are these parenthesis and brackets that I can't remove.