I want to replace the values of column x s1_, s2_, s9_ and s10_ by s01_, s02_, s09_ and s10_. I can easily do it for each case (e.g. s1_) but not for all (my regex knowledge is short).
How can I do all those replacements without repeating myself?
library(tidyverse)
df <- tibble( x = c('s1_', 's2_', 's9_', 's10_'))
pattern <- 's1_'
replacement <- 's01_'
stringr::str_replace(df$x, pattern, replacement)
#> [1] "s01_" "s2_" "s9_" "s10_"
Created on 2020-11-12 by the reprex package (v0.3.0)