replace - Replacing a double quote in an R data frame read from csv -


in addition post:

how find , replace double quotes in r data frame

i ran strange problem. using tips wrote short program:

setclass("char.with.deleted.quotes") setas("character", "char.with.deleted.quotes",        function(from) as.character(gsub('„',"xxx", as.character(from), fixed = true)))   tmp = read.csv2("./test.csv", header=true, sep=";", dec=",",                 colclasses = c("character","char.with.deleted.quotes"))  temp <- gsub('„', "xxx", tmp$name, fixed=true) print(temp) 

with output:

> source('test.r') [1] "this „test" "and „test"  [1] " " number               name 1    x-23 „test 2 k-33.01  , „test 

which reads dummy csv:

number;name x-23;this „test k-33.01;and „test 

my goal rid of double quote before word test. far not work. , because of double quote.

if instead choose replace different part of character work either read.csv2 , above definition of class or directly gsub saving temp variable.

now strange following. after running program copied 2 lines "temp <- gsub" , "print(temp)" manually command line:

> source('test.r') [1] "this „test" "and „test"  [1] "this „test" "and „test"  [1] " " number               name 1    x-23 „test 2 k-33.01  , „test >  > temp <- gsub('„', "xxx", tmp$name, fixed=true) > print(temp) [1] "this xxxtest" "and xxxtest" 

this whatever reason works , work if modify data frame directly:

> tmp$name <- gsub('„', "xxx", tmp$name, fixed=true) > print(tmp) number                 name 1    x-23 xxxtest 2 k-33.01  , xxxtest 

but if repeat command in program , run again, not work. , have no idea why.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -