【发布时间】:2019-11-28 15:50:12
【问题描述】:
我正在尝试用 R 中数据框同一行的另一列中的单词从一行中填充模板。
这是我想要做的一个例子:
x <- data.frame("replacement" = c("two", "ten"),
"text" = c("we had <replacement> books", "we had <replacement> books"),
"result" = c("we had two books", "we had ten books"))
我尝试使用 gsub,但它会替换所有单词而不是一个:
x$result <- gsub("\\<.+?\\>", x$replacement, x$text)
【问题讨论】: