在R的数据框中替换所有以n't结尾的单词

时间:2018-09-09 11:45:36

标签: r

我正在寻找一种解决方案,可以将以n't结尾的所有单词替换为2部分,例如“ has n't”为“ has not”或“ was n't”为“ was not”。

现在我有以下解决方案,但是我必须对所有想做的单词都做一遍:

  hero.service.ts:19 entered at service
  hero.service.ts:22 chnage getted ab
  detail.component.ts:23 text detail ab
  hero.service.ts:18 ___________________________
  hero.service.ts:19 entered at service
  hero.service.ts:22 chnage getted cd
  detail.component.ts:23 text detail cd
  hero.service.ts:18 ___________________________
  hero.service.ts:19 entered at service
  hero.service.ts:22 chnage getted  ef
  detail.component.ts:23 text detail  ef

1 个答案:

答案 0 :(得分:1)

这里是使用正则表达式grouping ()

的一个
gsub("(.*)(n\\'t)","\\1 not","haven't")
[1] "have not"