【发布时间】:2020-02-15 06:00:28
【问题描述】:
我知道在这个论坛上可能会提出类似的问题,但我觉得我的要求很特殊。 我有一个数据框,其中有一列具有以下值。 下面是刚刚的样本,它包含 1000 多个观察结果
报告的条款
"2 Left Axillary Lymph Nodes Resection"
"cardyoohyper"
"Ablation Breast"
"Hypercarido"
"chordiohyper"
"Adenocarcinoma Of Colon (Radical Resection And Cr)"
"myocasta"
"hypermyopa"
我有另一个具有以下规则的数据框:
数据框
我期待以下输出:
"2 Left Axillary Lymph Nodes Resection"
"carddiohiper"
"Ablation Breast"
"hipercardio"
"cardiohyper"
"Adenocarcinoma Of Colon (Radical Resection And Cr)"
"miocasta"
"hipermiopa"
我正在尝试使用 gsub 函数进行热编码,但我知道这需要很长时间。
pattern <- c("kardio, "carido", "cardyo", "cordio", "chordio")
replacement <- "cardio"
gusub(pattern,replacement,df$reportedterms)
使用上述方法,我需要每次对每个规则进行编码,并且每次都需要为 gsub 函数中的模式和替换创建不同的变量。
有解决这个问题的简单方法吗?
【问题讨论】:
标签: r replace pattern-matching stringr stringi