Extract substrings from before and inside parentheses
Source:R/before-inside-parens.R
parens-extractors.Rdbefore_parens() and inside_parens() extract substrings from
before or inside parentheses, or similar separators like brackets or curly
braces.
See split_by_parens() to split some or all columns in a data frame into
both parts.
Arguments
- string
Vector of strings with parentheses or similar.
- sep
String. What to split by. Either
"parens","brackets","braces", or a length-2 vector of custom separators. See examples forsplit_by_parens(). Default is"parens".
Value
String vector of the same length as string. The part of string
before or inside sep, respectively.
Examples
x <- c(
"3.72 (0.95)",
"5.86 (2.75)",
"3.06 (6.48)"
)
before_parens(string = x)
#> [1] "3.72" "5.86" "3.06"
inside_parens(string = x)
#> [1] "0.95" "2.75" "6.48"