The answers to similar questions on adding leading zeros do not work for me. I have a data.frame with just 1 column but many thousands or rows. The entries are of data type num. Some of the numeric values are 10 digits in length (which is correct) but some are 9 digits in length and others 8 digits in length. I want all entries to be 10 digits in length, and so shorter numbers need to be preceded by leading zeros. The entries that are already 10 digits are to be ignored. I am just beginner in R so am having difficulty. Any help will be appreciated. I have tried
paste (rep)
sprintf
but am just getting into a mess. Ideally, I want to keep the data.frame as num but if I have to change to type char that would probably be oaky. Thanks.
I tried previous answers but got this error
Error in sprintf("%010d", CHI3$DoB.Chi) : invalid format '%010d'; use format %f, %e, %g or %a for numeric objects