Extracting values within bracket in R

Issue

I have a df with column named ‘error (range)‘ containing the values with error range like below,

error (range)
25 (20 – 30)
42 (39 – 48)
35 (32 – 38)

But I want to extract the values and my df columns should look like,

error error_min error_max
25 20 30
42 39 48
35 32 38

Can anyone help me with the coding in R to achieve this ?

Solution

library(tidyverse)
df %>%
   set_names('error')%>%
   separate(error, c('error', 'error_min', 'error_max'), 
                convert = TRUE, extra = 'drop')

  error error_min error_max
1    25        20        30
2    42        39        48
3    35        32        38

Answered By – onyambu

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.