R newbie. I am trying to remove the, \" from the beginning and end of a line in a dataframe. I do not want to remove if the quotation is not the first or last character. I\'
you can trim a quotation mark from the end of the string like this:
x <- gsub('"$','',x)
and from the beginning of the string like this:
x <- gsub('^"','',x)
since the characters $
and ^
match the end and beginning of the string. For example:
myData<-data.frame(foo=c('"asdf"','ASDF'),
bar=c('jkl;','"JKL;"'))
myData
#> foo bar
#>1 "asdf" jkl;
#>2 ASDF "JKL;"
# trim the quote characters from myData$foo
myData$foo <- gsub("^\"|\"$", "", myData$foo)
myData
#> foo bar
#>1 asdf jkl;
#>2 ASDF "JKL;"