我有以下字符串:
a = "in the year 2010-01-01 there was a red dog and in the year 2011-01-01 there was a blue cat"
My Problem:在上面的字符串中,我想用2011替换every 2010,用2012替换every 2011.
我try 了以下代码:
b = gsub("2010", "2011", a)
b = gsub("2011", "2012", b)
但它覆盖了我的进步!
我用3条简短的声明做到了这一点:
b = gsub("2010", "temp", a)
b = gsub("2011", "2012", b)
b = gsub("temp", "2011", b)
但是,有没有一种更快的方法在一行代码中完成这项工作?