0

I am using R studio, and I have a data frame of 7 variables. One of the variables is months, and in this column I want to add leading zeros to the single digits (ex= 7 would be 07 but 12 would remain as 12). How would I do this, where only the single digit numbers in this column get leading zeros but the double digits remain the same?? Please help

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

We can use sprintf

df1$months <- sprintf('%02d', df1$months)
akrun
  • 874,273
  • 37
  • 540
  • 662