first of all, I have read through the following posts (R: keep leading zero, and again, and this one, and this one, or this one.), and my question is not answered by any of them.
I try to add a leading zero to the ID
column. The file is imported from excel, I am not sure how to upload to here. Probably not able to replicate the process to you.
When I use any of the following code to add a leading zero
formatC(data$col,width=5,format="s",flag="0")
sprintf("%05s",data$col)
gsub('\\s','0',data$col)
all of them gave me a whitespace before the string, instead of a zero. e.g." 4097"
I also try to trim down any spacetrimws(sort$DlrNbr, which = c("both", "left", "right"))
, and re-try add leading zero, still failed.
Do you have any idea what is going on? Any insight is helpful!