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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -