James, How about sprintf('%05d', 210)
It works for fixed length id numbers. Dave From: James Splinter <james.r.splin...@gmail.com> To: R-help@r-project.org Date: 12/21/2010 02:44 PM Subject: [R] Keeping Leading Zeros, Treating numbers as text Sent by: r-help-boun...@r-project.org Hello, I have a data set, with some numerical values, some non-numerical data, my issue is that I need to preserve my ID numbers (numerics) with the leading zeros, but when I import the data into R (it's in .csv format) using the read.csv(" ") command, it turns all the ID numbers (Example: 00210) into numbers, removing the leading zeros, so I end up with 210. I tried using the "as.is=" command on the column that I wanted to treat as text, but it had no effect. Any help would be very much appreciated, Thanks, James [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.