Learn R Programming

scrutiny (version 0.5.0)

parens-extractors: Extract substrings from before and inside parentheses

Description

before_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.

Usage

before_parens(string, sep = "parens")

inside_parens(string, sep = "parens")

Value

String vector of the same length as string. The part of string

before or inside sep, respectively.

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 for split_by_parens(). Default is "parens".

Examples

Run this code
x <- c(
  "3.72 (0.95)",
  "5.86 (2.75)",
  "3.06 (6.48)"
)

before_parens(string = x)

inside_parens(string = x)

Run the code above in your browser using DataLab