Issue
I have inherited an r project that has a dataframe with truncated text strings. Based on some responses in this forum, I have tried
temp$taname2 <- gsub("\bDistr\b", "District", temp$taname2)
This did not work. I tried
temp$taname2 <- gsub("Distr", "District", temp$taname2)
but this resulted in rows already containing the word "District" being changed to "Districtic", "Districtict", or similar. I also tried
temp$taname2[grep("\bDistr\b",temp$taname2)] <- "District"
but, alas, no luck.
I realise the answer is ridiculously simple but I haven't been able to work out how to do it.
Thanks in advance.
Solution
You need to make use of regular expressions as well as the gsub function. I think this question is answered here: In R, replace text within a string
Hope this helps.
Answered By - Kenty Ramdatt Answer Checked By - Marilyn (WPSolving Volunteer)