1

my data set has codes which are supposed to be 5 digits. However, there are a few with 4 digits. I want to add leading zeros in front of those values with 4 digits. I used the following code:

labos$postal1 <- sprintf("%05d", labos$postal)

This command added zeros in front of all the values, including those with 5 digits.

Help me add zeros just to the values with 4 digits.

duckmayr
  • 15,718
  • 3
  • 32
  • 50
alba
  • 11
  • 1

0 Answers0