【发布时间】:2016-08-02 14:59:31
【问题描述】:
我正在尝试在一组可能在措辞上略有不同的字符串上使用 gsub;
I went to the store last night
I went to the park yesterday
I went to starbucks this morning
我需要使用 gsub 来替换 'I going to...',但有时它会有一个 'the',有时它不会
类似这样的东西,但以下将无法正常工作
gsub('i went to [the|a-z]','REPLACED',string)
REPLACED last night
REPLACED yesterday
REPLACED this morning
【问题讨论】:
-
这样的?
gsub("I went to[ the]*(store|park|starbucks)","REPLACED",data) -
@user2100721 我相信他把它放在第二个代码块中。
-
@user2100721 它位于第二个块中。谢谢