Exporting .csv file dropping leading zeros

Hello,

I have a very basic R Script I am running in PowerBI to export a file, from Power Query:

write.table(dataset, file="Pam_list.csv", sep = ",", row.names = FALSE, append = FALSE, quote= FALSE)

The issue I am having is that the Customer Number has leading zeros: 0000048014.

When I export to a .csv, open with notepad, it drops the zeros so the result is 48014.

Any suggestions would be great, I am a n00b so I will probably have more questions.

Thank you!

I think the thing to do is convert the numbers to strings, formatting them so that they are padded with 0 to a given width.


testdf <- data.frame(rawnum=c(123,456,7890))


testdf$padded0 = formatC(testdf$rawnum,
                          width = 10,
                          flag = "0")

write.csv(testtib,
          file="test.csv",
          row.names = FALSE)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.