Replacing all occurrences of a pattern in a string
character, r
Solution
The second line from `?sub` explains:
sub and gsub perform replacement of the first and all matches respectively.
which should tell you to use `gsub` instead.
Problem
Used to run R with numbers and matrix, when it comes to play with strings and characters I am lost. I want to analyze some data where the time is read into R as follow: ``` >my.time.char[1] [1] "\"2011-10-05 15:55:00\"" ``` I want to end up with a string containing only: ``` "2011-10-05 15:55:00" ``` Using the function sub() (that i barely understand...), I got the following result: ``` > sub("(\")","",my.time.char[1]) [1] "2011-10-05 15:55:00\"" ``` This is closer to the format i am looking for, but I still need to get rid of the two last characters (`\"`).