How to extract lower and upper bound in numeric format from a confidence interval string?How can I plot data with confidence intervals?R - Bootstrapped Confidence Interval - Obtain Parameters of Upper and Lower BoundsHow to display several bootstrap confidence intervals on one plotHow can confidence intervals be numerically visualized in corrplot()?How to compute confidence Interval of the fitted value via nls()rAmCharts Scattered plot with Upper and lower confidence interval around Fitted valuesextract confidence intervals from binomial test in Rhow to add confidence interval as coloured area to a boxplot of predicted values in ggplot2?How to extract values of confidence interval from ggplot2 stat summary in R?Plotting a ggplot() when having the confidence interval upper and lower values
What's the correct term describing the action of sending a brand-new ship out into its first seafaring trip?
From system of coupled ODEs to separable ODE
How to skip replacing first occurrence of a character in each line?
Can a magnetic field of an object be stronger than its gravity?
What happened to all the nuclear material being smuggled after the fall of the USSR?
Smooth switching between 12v batteries, with toggle switch
How can Iron Man's suit withstand this?
How do I write "Show, Don't Tell" as an Asperger?
Traffic law UK, pedestrians
Aligning object in a commutative diagram
Who operates delivery flights for commercial airlines?
Company did not petition for visa in a timely manner. Is asking me to work from overseas, but wants me to take a paycut
How to supress loops in a digraph?
Why is c4 bad when playing the London against a King's Indian?
Why did Hela need Heimdal's sword?
Reading two lines in piano
Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP)/sleep apnea device?
How were concentration and extermination camp guards recruited?
Payment instructions from HomeAway look fishy to me
Is the decompression of compressed and encrypted data without decryption also theoretically impossible?
Pay as you go Or Oyster card
What can plausibly explain many of my very long and low-tech bridges?
How is it possible that Gollum speaks Westron?
Should I "tell" my exposition or give it through dialogue?
How to extract lower and upper bound in numeric format from a confidence interval string?
How can I plot data with confidence intervals?R - Bootstrapped Confidence Interval - Obtain Parameters of Upper and Lower BoundsHow to display several bootstrap confidence intervals on one plotHow can confidence intervals be numerically visualized in corrplot()?How to compute confidence Interval of the fitted value via nls()rAmCharts Scattered plot with Upper and lower confidence interval around Fitted valuesextract confidence intervals from binomial test in Rhow to add confidence interval as coloured area to a boxplot of predicted values in ggplot2?How to extract values of confidence interval from ggplot2 stat summary in R?Plotting a ggplot() when having the confidence interval upper and lower values
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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)
r
New contributor
add a comment |
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)
r
New contributor
add a comment |
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)
r
New contributor
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)
r
r
New contributor
New contributor
New contributor
asked May 27 at 12:31
FatetaFateta
826
826
New contributor
New contributor
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
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
add a comment |
mypattern <- '\[(\d+\.\d+) ; (\d+\.\d+)\]'
as.numeric(gsub(mypattern, '\1', confint))
as.numeric(gsub(mypattern, '\2', confint))
add a comment |
A different base R
possibility could be:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [2])
[1] "0.741" "263.917" "12.788" "0.680" "0.650" "0.719"
[1] "2.233" "402.154" "17.975" "2.450" "1.827" "2.190"
If you need it as a numeric vector:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [2])
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
add a comment |
Meanwhile, I came up with another base R
solution
lower <- as.numeric(sub(".]*", "", sub(";.*", "", confint)))
upper <- as.numeric(sub("].*", "", sub(".*;", "", 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
Thank you all!
add a comment |
You can use functions from the stringr library.
You can split strings with str_split()
according a specific character (;
in your case), then remove character with str_remove()
([
and ]
in your case) and you will obtain what you want.
str_remove(str_split_fixed(confint, ";", n = 2)[,1], '\[') %>% as.numeric()
# [1] 0.741 263.917 12.788 0.680 0.650 0.719
add a comment |
A tidyverse
solution:
library(dplyr)
library(tidyr)
df = data.frame(confint)
df = df %>%
mutate(confint = gsub("(\[|\])","",confint)) %>%
separate(confint,c("lower","upper"),";",convert=T)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Fateta is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56326130%2fhow-to-extract-lower-and-upper-bound-in-numeric-format-from-a-confidence-interva%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
edited May 27 at 12:45
answered May 27 at 12:41
G5WG5W
24.5k92345
24.5k92345
add a comment |
add a comment |
mypattern <- '\[(\d+\.\d+) ; (\d+\.\d+)\]'
as.numeric(gsub(mypattern, '\1', confint))
as.numeric(gsub(mypattern, '\2', confint))
add a comment |
mypattern <- '\[(\d+\.\d+) ; (\d+\.\d+)\]'
as.numeric(gsub(mypattern, '\1', confint))
as.numeric(gsub(mypattern, '\2', confint))
add a comment |
mypattern <- '\[(\d+\.\d+) ; (\d+\.\d+)\]'
as.numeric(gsub(mypattern, '\1', confint))
as.numeric(gsub(mypattern, '\2', confint))
mypattern <- '\[(\d+\.\d+) ; (\d+\.\d+)\]'
as.numeric(gsub(mypattern, '\1', confint))
as.numeric(gsub(mypattern, '\2', confint))
answered May 27 at 12:52
pzhaopzhao
21018
21018
add a comment |
add a comment |
A different base R
possibility could be:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [2])
[1] "0.741" "263.917" "12.788" "0.680" "0.650" "0.719"
[1] "2.233" "402.154" "17.975" "2.450" "1.827" "2.190"
If you need it as a numeric vector:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [2])
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
add a comment |
A different base R
possibility could be:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [2])
[1] "0.741" "263.917" "12.788" "0.680" "0.650" "0.719"
[1] "2.233" "402.154" "17.975" "2.450" "1.827" "2.190"
If you need it as a numeric vector:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [2])
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
add a comment |
A different base R
possibility could be:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [2])
[1] "0.741" "263.917" "12.788" "0.680" "0.650" "0.719"
[1] "2.233" "402.154" "17.975" "2.450" "1.827" "2.190"
If you need it as a numeric vector:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [2])
A different base R
possibility could be:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) gsub("[^0-9.-]+", "\1", x) [2])
[1] "0.741" "263.917" "12.788" "0.680" "0.650" "0.719"
[1] "2.233" "402.154" "17.975" "2.450" "1.827" "2.190"
If you need it as a numeric vector:
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [1])
sapply(strsplit(confint, " ; ", fixed = TRUE), function(x) as.numeric(gsub("[^0-9.-]+", "\1", x)) [2])
edited May 27 at 12:58
answered May 27 at 12:49
tmfmnktmfmnk
6,3861821
6,3861821
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
add a comment |
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
@Ronak Shah I updated my post according some of your ideas. Thank you :)
– tmfmnk
May 27 at 12:59
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
I realised it needed some more tweaking to get exact output but I think it was a similar approach. +1 to you.
– Ronak Shah
May 27 at 13:21
add a comment |
Meanwhile, I came up with another base R
solution
lower <- as.numeric(sub(".]*", "", sub(";.*", "", confint)))
upper <- as.numeric(sub("].*", "", sub(".*;", "", 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
Thank you all!
add a comment |
Meanwhile, I came up with another base R
solution
lower <- as.numeric(sub(".]*", "", sub(";.*", "", confint)))
upper <- as.numeric(sub("].*", "", sub(".*;", "", 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
Thank you all!
add a comment |
Meanwhile, I came up with another base R
solution
lower <- as.numeric(sub(".]*", "", sub(";.*", "", confint)))
upper <- as.numeric(sub("].*", "", sub(".*;", "", 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
Thank you all!
Meanwhile, I came up with another base R
solution
lower <- as.numeric(sub(".]*", "", sub(";.*", "", confint)))
upper <- as.numeric(sub("].*", "", sub(".*;", "", 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
Thank you all!
edited May 28 at 6:18
answered May 27 at 13:22
FatetaFateta
826
826
add a comment |
add a comment |
You can use functions from the stringr library.
You can split strings with str_split()
according a specific character (;
in your case), then remove character with str_remove()
([
and ]
in your case) and you will obtain what you want.
str_remove(str_split_fixed(confint, ";", n = 2)[,1], '\[') %>% as.numeric()
# [1] 0.741 263.917 12.788 0.680 0.650 0.719
add a comment |
You can use functions from the stringr library.
You can split strings with str_split()
according a specific character (;
in your case), then remove character with str_remove()
([
and ]
in your case) and you will obtain what you want.
str_remove(str_split_fixed(confint, ";", n = 2)[,1], '\[') %>% as.numeric()
# [1] 0.741 263.917 12.788 0.680 0.650 0.719
add a comment |
You can use functions from the stringr library.
You can split strings with str_split()
according a specific character (;
in your case), then remove character with str_remove()
([
and ]
in your case) and you will obtain what you want.
str_remove(str_split_fixed(confint, ";", n = 2)[,1], '\[') %>% as.numeric()
# [1] 0.741 263.917 12.788 0.680 0.650 0.719
You can use functions from the stringr library.
You can split strings with str_split()
according a specific character (;
in your case), then remove character with str_remove()
([
and ]
in your case) and you will obtain what you want.
str_remove(str_split_fixed(confint, ";", n = 2)[,1], '\[') %>% as.numeric()
# [1] 0.741 263.917 12.788 0.680 0.650 0.719
edited May 27 at 12:45
answered May 27 at 12:38
demarsylvaindemarsylvain
1,2722621
1,2722621
add a comment |
add a comment |
A tidyverse
solution:
library(dplyr)
library(tidyr)
df = data.frame(confint)
df = df %>%
mutate(confint = gsub("(\[|\])","",confint)) %>%
separate(confint,c("lower","upper"),";",convert=T)
add a comment |
A tidyverse
solution:
library(dplyr)
library(tidyr)
df = data.frame(confint)
df = df %>%
mutate(confint = gsub("(\[|\])","",confint)) %>%
separate(confint,c("lower","upper"),";",convert=T)
add a comment |
A tidyverse
solution:
library(dplyr)
library(tidyr)
df = data.frame(confint)
df = df %>%
mutate(confint = gsub("(\[|\])","",confint)) %>%
separate(confint,c("lower","upper"),";",convert=T)
A tidyverse
solution:
library(dplyr)
library(tidyr)
df = data.frame(confint)
df = df %>%
mutate(confint = gsub("(\[|\])","",confint)) %>%
separate(confint,c("lower","upper"),";",convert=T)
answered May 27 at 14:12
FinoFino
816316
816316
add a comment |
add a comment |
Fateta is a new contributor. Be nice, and check out our Code of Conduct.
Fateta is a new contributor. Be nice, and check out our Code of Conduct.
Fateta is a new contributor. Be nice, and check out our Code of Conduct.
Fateta is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56326130%2fhow-to-extract-lower-and-upper-bound-in-numeric-format-from-a-confidence-interva%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown