Suppose a vector including some confidence intervals as below
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]")
I want to have two new vectors one including the lower Limits in numeric format as
lower <- c(0.741, 263.917, 12.788, 0.680, 0.650 , 0.719)
and othe including the upper Limits in numeric format like
upper <- c(2.233, 402.154, 17.975, 2.450, 1.827, 2.190)
A base R solution
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
mypattern <- '\\[(\\d+\\.\\d+) ; (\\d+\\.\\d+)\\]'
as.numeric(gsub(mypattern, '\\1', confint))
as.numeric(gsub(mypattern, '\\2', confint))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With