# Call `split_by_parens()` on data like these:
df1 <- tibble::tribble(
~drone, ~selfpilot,
"0.09 (0.21)", "0.19 (0.13)",
"0.19 (0.28)", "0.53 (0.10)",
"0.62 (0.16)", "0.50 (0.11)",
"0.15 (0.35)", "0.57 (0.16)",
)
# Basic usage:
df1 %>%
split_by_parens()
# Name specific columns with `cols` to only split those:
df1 %>%
split_by_parens(cols = drone)
# Pivot the data into a longer format
# by setting `transform` to `TRUE`:
df1 %>%
split_by_parens(transform = TRUE)
# Choose different column names or
# name suffixes with `end1` and `end2`:
df1 %>%
split_by_parens(end1 = "beta", end2 = "se")
df1 %>%
split_by_parens(
transform = TRUE,
end1 = "beta", end2 = "se"
)
# With a different separator...
df2 <- tibble::tribble(
~drone, ~selfpilot,
"0.09 [0.21]", "0.19 [0.13]",
"0.19 [0.28]", "0.53 [0.10]",
"0.62 [0.16]", "0.50 [0.11]",
"0.15 [0.35]", "0.57 [0.16]",
)
# ... specify `sep`:
df2 %>%
split_by_parens(sep = "brackets")
# (Accordingly with `{}` and `"braces"`.)
# If the separator is yet a different one...
df3 <- tibble::tribble(
~drone, ~selfpilot,
"0.09 <0.21>", "0.19 <0.13>",
"0.19 <0.28>", "0.53 <0.10>",
"0.62 <0.16>", "0.50 <0.11>",
"0.15 <0.35>", "0.57 <0.16>",
)
# ... `sep` should be a length-2 vector
# that contains the separating elements:
df3 %>%
split_by_parens(sep = c("<", ">"))
Run the code above in your browser using DataLab