I created a data frame (out of csv file) that will be used to correct spelling errors in the text I'm working with:
df1 <- data.frame(
old_text = c("typo1",
"typo2",
"typo3"),
fixed_text = c("typo1_fixed",
"typo2_fixed",
"typo3_fixed"))
I'm now trying to go through the actual text (located in a separate data frame) and if there's a typo, fix it:
df2 <- data.frame(
text= c("typo1", "Hi", "typo2", "Bye", "typo3"))
I've tried mapply but it doesn't work:
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"
Any help would be appreciated!