r - remove a character from the entire data frame -
i have dataframe various columns, of data within columns contain double quotes, want remove these, eg:
id name value1 value2 "1 x a,"b,"c x" "2 y d,"r" z"
i want this:
id name value1 value2 1 x a,b,c x 2 y d,r z
i use lapply
loop on columns , replace "
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 class
can changed 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))
Comments
Post a Comment