I'm trying to remove the '+' character present inside one of the string element of a data frame. But I'm not able to find a way out of it.
Below is data frame.
txtdf <- structure(list(ID = 1:9, Var1 = structure(c(1L, 1L, 1L, 1L, 4L,
5L, 5L, 2L, 3L), .Label = c("government", "parliament", "parliment",
"poli+tician", "politician"), class = "factor")), .Names = c("ID",
"Var1"), class = "data.frame", row.names = c(NA, -9L))
# ID Var1
# 1 government
# 2 government
# 3 government
# 4 government
# 5 poli+tician
# 6 politician
# 7 politician
# 8 parliament
# 9 parliment
I tried two ways, neither of them gave the expected results:
Way1
txtdf <- gsub("[:punct:]","", txtdf)
# [1] "goverme" "goverme" "goverme" "goverme" "oli+iia" "oliiia" "oliiia"
# [8] "arliame" "arlime"
I don't understand what's wrong here. I want the '+' characters to be replaced with no value for the 5th element alone, but all the elements are edited as above.
Way2
txtdf<-gsub("*//+","",txtdf)
# [1] "government" "government" "government" "government" "poli+tician"
# [6] "politician" "politician" "parliament" "parliment"
Here there is no change at all. What I think I've tried is, i tried to escape the + character using double slashes.