Skip to content

Keeping Leading Zeros, Treating numbers as text

5 messages · James Splinter, Bert Gunter, David L Lorenz +2 more

#
Try reading the csv file with, say, Notepad. I think you may find that
the problem is that Excel assumes the column is numeric and strips off
the zeros before saving the file. So you need to tell it that the ID
columns are character before saving.

Then you need to read the Help page for read.csv more carefully,
noting, in particular, the "colClasses" argument.

-- Bert

On Tue, Dec 21, 2010 at 12:43 PM, James Splinter
<james.r.splinter at gmail.com> wrote:

  
    
#
On Dec 21, 2010, at 4:11 PM, Bert Gunter wrote:

            
If Excel turns out to be the culprit, there is an equivalent operation  
to the colClasses specification which you can do to prevent leading  
zeros from being dropped. Select the entire column by clicking on the  
column letter at the top margin of the sheet and then choose Format/ 
Cells/... and pick "Text". The same sort of preparation can also save  
you grief with Date types in Excel or OO.org.
David Winsemius, MD
West Hartford, CT
#
Use the colClasses argument with a vector of character strings naming the types you want each column to have, and specify "character" for your id column.
"James Splinter" <james.r.splinter at gmail.com> wrote:

            
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.