'how to replace none-breaking space in the whole df [duplicate]

I have two obs one has None-breaking space and another has regular space. I want to make them the same. how should I do the replace one with another? Is it a way to take care such issue? I spend an hour to find those two are in fact not the SAME. :(

the one in old is: [1] 45 72 79 2e 20 4d 65 61 6e 20 43 6f 72 70 75 73 63 75 6c 61 72 20 56 6f 6c 75 6d 65

the one in new is: [1] 45 72 79 2e c2 a0 4d 65 61 6e c2 a0 43 6f 72 70 75 73 63 75 6c 61 72 c2 a0 56 6f 6c 75 6d 65

df<-structure(list(new = c("Ery. Mean Corpuscular Volume", "Ery. Mean Corpuscular Volume"
), old = c("Ery. Mean Corpuscular Volume", "Ery. Mean Corpuscular Volume"
)), row.names = c(NA, -2L), class = "data.frame")

Is it a way to standardize all those spaces in one setting? Too hard to find that they are in fact different.

enter image description here

r


Solution 1:[1]

Should work with gsub

x <- "I\u00A0am\u000Aa\u000Btotal\u0020mess"
y <- "I am a total mess"

identical(x, y)
# [1] FALSE

identical(gsub("\\s", " ", x), y)
# [1] TRUE

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Merijn van Tilborg