我创建了一个数据框(来自csv文件),用于纠正我正在处理的文本中的拼写错误:
df1 <- data.frame(
old_text = c("typo1",
"typo2",
"typo3"),
fixed_text = c("typo1_fixed",
"typo2_fixed",
"typo3_fixed"))
我现在正在try 浏览实际文本(位于单独的数据框中),如果有拼写错误,请进行修复:
df2 <- data.frame(
text= c("typo1", "Hi", "typo2", "Bye", "typo3"))
我try 了mapply,但不起作用:
df2$text[grepl(df1$old_text, df2$text)] = mapply(function(x,y) gsub(x,y,df2$text[grepl(df1$old_text, df2$text)]), df1$old_text, df1$new_text)
"Error in mapply(function(x, y) gsub(x, y, df2$text[grepl(df1$old_text, :
zero-length inputs cannot be mixed with those of non-zero length"
任何帮助都将不胜感激!