我该如何使用
purrr::map()
来返回以下示例中的 for 循环结果呢?vct_string <- c("old ccar","new carr", "house", "oold house")
df_correction <- data.frame(
pattern = c("ccar", "carr", "oold"),
replacement = c("car", "car", "old"),
stringsAsFactors = FALSE
)
for(i in 1:nrow(df_correction)){
vct_string <- pmap(df_correction, gsub, x = vct_string)[[i]]
}
> vct_string
[1] "old car" "new car" "house" "old house"