gpt4 book ai didi

r - 创建正则表达式以从行值中删除字符串和字符

转载 作者:行者123 更新时间:2023-12-02 18:08:00 25 4
gpt4 key购买 nike

我的数据框中有一列,如下所示:

branching_loc <- c("([preliminary_arm_1][antibiotic_arm] = '1') and [was_review_done]='1'",
"[preliminary_arm_1][antibiotic_arm] = '1' and [was_review_done]=='1'",
"[preliminary_arm_1][antibiotic_arm] = '1' and [was_review_done]=='1'",
"[preliminary_arm_1][antibiotic_arm] = '1' and [was_review_done]=='1'")

df <- data.frame(branching_loc)

现在我确实想仅从此行值中删除[preliminary_arm_1]。我正在努力用 R 语言创建正则表达式来执行此操作。请帮忙

最佳答案

可能的解决方案:

library(tidyverse)

df %>%
mutate(branching_loc = str_remove(branching_loc, "\\[preliminary_arm_1\\]"))

#> branching_loc
#> 1 ([antibiotic_arm] = '1') and [was_review_done]='1'
#> 2 [antibiotic_arm] = '1' and [was_review_done]=='1'
#> 3 [antibiotic_arm] = '1' and [was_review_done]=='1'
#> 4 [antibiotic_arm] = '1' and [was_review_done]=='1'

关于r - 创建正则表达式以从行值中删除字符串和字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72880246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com