我复制了我的问题的一个简单版本.我基本上是想用西班牙语替换声明一栏中的英语单词,即所有声明.
library(tidyverse)
english <- c('hello','world','my','name', 'is')
spanish <- c('hola','mundo','mi','nombre', 'es')
statement <-c('Hello my name is john doe',' hello world','my name is world','hello john, my world is','jane is my world ')
df <- data.frame(english,spanish,statement)
df
我试过了
df %>%
str_replace_all(statement, c(df$english), c(df$spanish))
和
str_replace_all(statement, c(df$english), c(df$spanish)).
第二次try 让我离答案更近了一步.只有一个答案被替换了.