这是您完成任务的起点:
library(dplyr)
library(stringr)
df %>%
mutate(across(everything(), ~sub(".*oz ", '', .))) %>%
mutate(across(everything(), ~sub(".*OZ ", '', .))) %>%
mutate(across(everything(), ~str_replace(., " \\s*\\([^\\)]+\\)", "")))
ingredient1 ingredient2 ingredient3
<chr> <chr> <chr>
1 pisco egg white lime juice
2 Plymouth gin egg white lemon juice
3 Plymouth gin egg white Dolin dry vermo
4 rye simple syrup lemon juice
5 white rum lime juice simple syrup
6 white rum lime juice honey syrup
7 white rum lime juice simple syrup
8 Scotch Cherry Herring sweet vermouth
9 Cognac heavy cream Demerara syrup
10 white rum lime juice grapefruit juice
11 bourbon grapefruit juice honey syrup
12 Absolut Citron vodka Cointreau cranberry juice
13 bourbon lemon juice honey syrup
数据:
structure(list(ingredient1 = c("2 oz pisco (40% abv)", "1 1/2 oz Plymouth gin",
"2 oz Plymouth gin", "2 oz rye (50% abv)", "2 oz white rum (40% abv)",
"2 oz white rum (40% abv)", "2 oz white rum (40% abv)", "1 oz Scotch (43% abv)",
"2 oz Cognac (41% abv)", "2 oz white rum (40% abv)", "2 oz bourbon (45% abv)",
"1 1/2 oz Absolut Citron vodka", "2 OZ bourbon (47% abv)"), ingredient2 = c("1 oz egg white",
"1 oz egg white", "1 oz egg white", "3/4 oz simple syrup", "0.875 oz lime juice",
"3/4 oz lime juice", "3/4 oz lime juice", "3/4 oz Cherry Herring",
"1 oz heavy cream", "3/4 oz lime juice", "1 oz grapefruit juice",
"3/4 oz Cointreau", "3/4 oz lemon juice"), ingredient3 = c("3/4 oz lime juice",
"3/4 oz lemon juice", "1/2 oz Dolin dry vermo", "0.625 oz lemon juice",
"3/4 oz simple syrup", "3/4 oz honey syrup", "3/4 oz simple syrup",
"3/4 oz sweet vermouth", "1/4 oz Demerara syrup", "1/2 oz grapefruit juice",
"1/2 oz honey syrup", "3/4 oz cranberry juice", "3/4 oz honey syrup"
)), row.names = c(NA, -13L), spec = structure(list(cols = list(
ingredient1 = structure(list(), class = c("collector_character",
"collector")), ingredient2 = structure(list(), class = c("collector_character",
"collector")), ingredient3 = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = "\t"), class = "col_spec"), problems = <pointer: 0x00000179794ebf20>, class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))