Re: [R] String replace

2019-04-03 Thread Ivan Krylov
On Wed, 3 Apr 2019 15:01:37 +0100 Graham Leask via R-help wrote: Suppose that `BHC$Date` contains a string "M_24". You do: > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_2" , > "01-04-2017")) before you have a chance to do: > BHC <-BHC %>% mutate ( Date = stringr :: str_re

Re: [R] String replace

2019-04-03 Thread Sarah Goslee
Try reversing the order, or extending the to-replace bit. "M_1" is finding and replacing "M_10", "M_11", etc. "M_2" is finding and replacing "M_20", "M_21", etc. So M_14 becomes "01-03-20174" In the future, a toy dataset would help with the reproducible example aspect, and make your question eas

[R] String replace

2019-04-03 Thread Graham Leask via R-help
I’m attempting to replace a string variable that normally works fine. However when trying to do this with a string in the form of a date the output becomes corrupted. See below: BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_1" , "01-03-2017")) BHC <-BHC %>% mutate ( Date =