如何从置信区间字符串中提取数字格式的上下限?

Fat*_*eta 10 r

假设一个包含一些置信区间的向量如下

confint <- c("[0.741 ; 2.233]", "[263.917 ; 402.154]", "[12.788 ; 17.975]", "[0.680 ; 2.450]", "[0.650 ; 1.827]", "[0.719 ; 2.190]")
Run Code Online (Sandbox Code Playgroud)

我想有两个新矢量,其中一个包含数字格式的下限

lower <- c(0.741, 263.917, 12.788, 0.680, 0.650 , 0.719)
Run Code Online (Sandbox Code Playgroud)

其他包括数字格式的上限,例如

upper <- c(2.233, 402.154, 17.975, 2.450, 1.827, 2.190)
Run Code Online (Sandbox Code Playgroud)

G5W*_*G5W 12

基础R解决方案

lower =  as.numeric(sub(".*?(\\d+\\.\\d+).*", "\\1", confint))
upper =  as.numeric(sub(".*\\b(\\d+\\.\\d+).*", "\\1", confint))

lower
[1]   0.741 263.917  12.788   0.680   0.650   0.719
upper
[1] 2.233 402.154  17.975   2.450   1.827   2.190
Run Code Online (Sandbox Code Playgroud)