Skip to content
Prev 273551 / 398506 Next

Issue with read.csv treatment of numerics enclosed in quotes (and a confession)

Hi Chris,

Yes, you're missing something: the colClasses argument to read.csv.

Given a tiny little csv file that looks like this:

1,2,3,"01234"
4,5,6,"00011"
7,8,0,"00000"
V1 V2 V3    V4
1  1  2  3 01234
2  4  5  6 00011
3  7  8  0 00000
'data.frame':	3 obs. of  4 variables:
 $ V1: int  1 4 7
 $ V2: int  2 5 8
 $ V3: int  3 6 0
 $ V4: chr  "01234" "00011" "00000"

That should do what you want.

Not that you should need it, but sprintf() is a neater way to pad out
numeric to character values:
[1] "00012"
[1] "01223"
[1] "0000012"
Hope that solves your problem,
Sarah
On Wed, Oct 5, 2011 at 8:24 PM, Chris Conner <connerpharmd at yahoo.com> wrote: