[R-sig-DB] CSV input returns unexpected and unwanted numbers.

Jim Burke j@burke @end|ng |rom e@rth||nk@net
Thu Apr 23 08:23:30 CEST 2009


Thanks Markus!!!

Your suggestion worked perfectly. Those 15 digit
numbers point to the lowest USA census level
called a census block.

Then my problem may have caused been saving and
reusing a weird R workspace.

Most grateful,
Jim Burke



Markus Jäntti wrote:
> Jim Burke wrote:
>> I am having extreme trouble inputting a csv file.
>> Previously this worked flawlessly.
>>
>> Resolution attempts tried. Still problems.
>> . Rebooting the PC
>> . Defrag the PC
>> . Reboot with the shift key down (don't run
>>  startup items).
>> . Using old R 2.81
>>
>> PROBLEM is the first column incorrectly comes
>> out in scientific notation.
>>
>> My csv data file named h01369_short_blk.csv.
>> The data file is below.
>> ===================================
>> "sctbkey","district"
>> "480019501001000",8
>> "480019501001001",8
>> "480019501001002",8
>> "480019501001003",8
>> "480019501001004",8
>> "480019501001005",8
>> "480019501001006",8
>>
>> Using R 9.0 on Windows XP I read it as follows.
>> The syntax is straight from help(read.csv).
>> ====================================
>> all_hd_df <- read.csv("h01369_short_blk.csv", header = TRUE,
>>             sep = ",", quote="\"", dec=".",
>>             fill = TRUE, comment.char="")
>>
>> Output
>> WHY THE SCIENTIFIC NUMBERS? I expected
>> 480019501001000 for the first one
>> ====================================
>>  > all_hd_df
>>       sctbkey district
>> 1 4.800195e+14        8
>> 2 4.800195e+14        8
>> 3 4.800195e+14        8
>> 4 4.800195e+14        8
>> 5 4.800195e+14        8
>> 6 4.800195e+14        8
>> 7 4.800195e+14        8
>>
>> Any suggestions?
>
> I can't answer the why part, but you can convert to strings by issuing
>
> all_hd_df$sctbkey <- as.character(all_hd_df$sctbkey)
>
> you should probably be able to use colClasses in the call to read.csv 
> to make it input as a character string.
>
> Markus
>
>>
>> Thanks,
>> Jim Burke
>>
>> _______________________________________________
>> R-sig-DB mailing list -- R Special Interest Group
>> R-sig-DB using stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-db
>>
>
>




More information about the R-sig-DB mailing list