I have been working on some data cleaning program in R and I have run into a problem. I am trying to replace the special characters like "@" with their character counterparts "at".
I have tried sub
, gsub
and setNames
and even replace
.
All of these produce the same result: it just gives me a ton of NA
s in my data.
I have a sample of what my data looks like just for reference.
Just imagine that I cannot see where all of the @ signs are, I want to search the entire data set and replace all of them. My actual dataset has 50 columns so going by column won't work.
################## EDIT ##################
aa <- read.csv("C:/Users/Zander Kent/Documents/Data Cleaning/sample dataset.csv", header = T, na.strings=c("", " ","NA"))
aaa <- data.frame(aa)
abc <- as.data.frame(apply(aaa, 2, function(x) gsub(" @ ", "at", x)))
write.csv(abc, file="C:/Users/Zander Kent/Documents/Data Cleaning/clean_2.csv")
link to data in google.drive Sample Data
I tried one of the answers and it worked on a very small data set 10x10 but when I tried it on my entire dataset it didn't do anything. all of the special characters were still there. There were no error messages the code ran through without any problems.