remove a character from the entire data frame

To remove $ you have to escape it \\\$. Try:

df[] <- lapply(df, gsub, pattern="\\\$", replacement="")

I would use lapply to loop over the columns and then replace the " using gsub.

df1[] <- lapply(df1, gsub, pattern='"', replacement='')
df1
#  ID name value1 value2
#1  1    x  a,b,c      x
#2  2    y    d,r      z

and if need the class can be changed with type.convert

df1[] <- lapply(df1, type.convert)

data

df1 <-  structure(list(ID = c("\"1", "\"2"), name = c("x", "y"),
value1 = c("a,\"b,\"c", 
"d,\"r\""), value2 = c("x\"", "z\"")), .Names = c("ID", "name", 
"value1", "value2"), class = "data.frame", row.names = c(NA, -2L))

One option would be to use apply() along with the gsub() function to remove all double quotation marks:

df <- data.frame(ID=c("\"1", "\"2"),
                 name=c("x", "y"),
                 value1=c("a,\"b,\"c", "d,\"r\""),
                 value2=c("x\"", "z\""))

df <- data.frame(apply(df, 2, function(x) {
                                  x <- gsub("\"", "", x)
                              })

> df
  ID name value1 value2
1  1    x  a,b,c      x
2  2    y    d,r      z

Tags:

R

Dataframe