I am trying to pad a string tidyverse.For example, i want to:
- detect certain format word, like "1" by using str_detect;
- paste such character on both side with different string: left side is "0", right side is ".00";
I learned that str_pad has "side=both",but how can I achieve my purpose? Thanks~~!
here is my code:
jimma3 <- jimma2 %>%
mutate(
Enterdateofexam2 = if_else(str_detect(Enterdateofexam2, "\\d"),
str_pad(as.character(Enterdateofexam2), 5, side = "both", pad = ".")
)
The problem is that I can only define one format (".") with width 1 in pad=" ", but what if i want to paste different string on both side and turn it into like :"01.00"? thanks a lot~!