R programming language resources › Forums › Data manipulation › reading csv huge number as string
- This topic has 2 replies, 2 voices, and was last updated 14 years, 6 months ago by
danko.
- AuthorPosts
- September 22, 2010 at 7:28 pm #400
danko
MemberHello to everyone.
I have CSV which is having “ID” field with a very big number 30665783822000811
When I load file
df <- tryCatch(read.csv(infile, sep=",",header=T),error=c) the number changes by little bit. May I tell R to read as string so will no longer to round incorrectly? thank you to helping. DANKO. output and input file. ID is almost last column. You can see in file number of 30665783822000811 changes to 30665783822000812 Others are also the change. c(30665783822000812, 30665783822000812, 30776079583003384, 30776079583003384, 31038814682008480, 31038814682008480, 31085247614009460, 31085247614009460, 31171634641011956, 31171634641011956, 31357713785015660, 31357713785015660, 31491106138000808, 31491106138000808, 31640124796002716, 31640124796002716, 32016088837006768, 32016088837006768, 32324417329009216, 32324417329009216, 33250902212000224, 33250902212000224, 33357470812002116, 33357470812002116, 33396845122004252, 33396845122004252, 33440823952006504, time,LSI,bidpz,askpz,price,mybidsz,myasksz,totbidsz,totasksz,pegdiff,fillsz,fillpz,id,exectype 1285075866,0.467419,17.4100,17.4700,17.4200,0,5,4,1,0.0000,0,0.0000,30665783822000811,0 1285075892,0.308993,17.4100,17.4300,17.4100,0,5,4,1,0.0000,0,0.0000,30665783822000811,4 1285075978,0.049906,17.4100,17.4700,17.4400,5,0,3,3,0.0000,0,0.0000,30776079583003386,0 1285076106,1.3e-05,17.4100,17.4600,17.4300,5,0,4,4,0.0000,0,0.0000,30776079583003386,4 1285076240,2.474414,17.3600,17.3800,17.3800,5,0,4,4,0.0000,0,0.0000,31038814682008480,0 1285076269,0.057438,17.3700,17.4100,17.3800,5,0,5,1,0.0000,0,0.0000,31038814682008480,4 1285076286,0.26067,17.3700,17.4100,17.3700,5,0,3,1,0.0000,0,0.0000,31085247614009461,0 1285076376,0,17.3700,17.4100,17.3700,5,0,4,1,0.0000,0,0.0000,31085247614009461,4 1285076376,0,17.3700,17.4100,17.3700,5,0,4,1,0.0000,0,0.0000,31171634641011957,0 1285076463,1.479583,17.3700,17.3700,17.3800,5,0,1,1,0.0000,0,0.0000,31171634641011957,4 1285076559,0.010071,17.4100,17.4200,17.3900,5,0,5,1,0.0000,0,0.0000,31357713785015660,0 1285076684,4.517916,17.4900,17.5200,17.5100,5,0,3,4,0.0000,0,0.0000,31357713785015660,4 1285076692,0.912134,17.4900,17.5200,17.5100,5,0,3,4,0.0000,0,0.0000,31491106138000807,0 1285076841,3.104893,17.5300,17.5700,17.5500,5,0,5,3,0.0000,5,17.5200,31491106138000807,2
September 27, 2010 at 7:30 pm #402seanpor
Memberadd the parameter colClasses=’character’ and *all* columns will stay in character format – this is what I do… then I validate each column and convert each with the appropriate validation.
alternatively you could say something like
df <- read.csv(infile, sep=",",header=T, colClasses= c('character', rep.int('numeric', 14) ) ) so the first column will be read in as character then the rest of them will be read in as numeric. Sean
October 8, 2010 at 7:32 pm #404danko
MemberExcellent. Thank you Sean. That works as intended.
Danko.
- AuthorPosts
- You must be logged in to reply to this topic.