Consider the following
foo <-
c("V_7_101110_V", "V_7_101110_V", "V_9_101110_V", "V_9_101110_V",
"V_9_s101110_V", "V_9_101110_V", "V_9_101110_V", "V_11_101110_V",
"V_11_101110_V", "V_11_101110_V", "V_11_101110_V", "V_11_101110_V",
"V_17_101110_V", "V_17_101110_V")
what I'm trying to obtain is to add a zero in front of numbers below 10,
as in
c("V_07_101110_V", "V_07_101110_V", "V_09_101110_V", "V_09_101110_V",
"V_09_101110_V", "V_09_101110_V", "V_09_101110_V", "V_11_101110_V",
"V_11_101110_V", "V_11_101110_V", "V_11_101110_V", "V_11_101110_V",
"V_17_101110_V", "V_17_101110_V")
I'm able to do this on the emacs buffer through query-replace-regexp
C-M-%
search for
V_\(.\)_
and substitute with
V_0\1_
but I completely ignore how to do it with gsub within R
and the help is quite complicate to understand
(at least to me, at this moment in time)
I can search the vector through
grep("V_._", foo)
but I always get errors either on
gsub('V_\(.\)_', 'V_0\1_', foo)
or I get not what I'm looking for on
gsub('V_._', 'V_0._', foo)
gsub('V_._', 'V_0\1_', foo)
Thanks in advance