0

I am importing a simple CSV file using read.csv with a few columns and numbers with many decimals. But in R the numbers only show up to 3 decimals. I read the read.table help but there is no mention of any option to decide how many decimals are being imported.

Total distance in cell_m    YYYYMM  tblCells 2012 new_Cellno    lat1    lon1    lat2    lon2
34049.62615 201201  458125  59.175  -169.0751445    58.95   -168.5549133
17761.45071 201201  458127  59.175  -168.0346821    58.95   -167.5144509
35.99240908 201201  458156  59.175  -152.9479769    58.95   -152.4277457
660775.5066 201201  458157  59.175  -152.4277457    58.95   -151.9075145
757159.5086 201201  458158  59.175  -151.9075145    58.95   -151.3872832
492577.9578 201201  458159  59.175  -151.3872832    58.95   -150.867052

and when they are imported they look like this:

Total.distance.in.cell_m YYYYMM tblCells.2012.new_Cellno   lat1      lon1  lat2      lon2 SECA
1                15927.873 201202                   456785 59.175 -177.3913 58.95 -176.8696    0
2               389951.316 201202                   456786 59.175 -176.8696 58.95 -176.3478    0
3               492503.129 201202                   456787 59.175 -176.3478 58.95 -175.8261    0
4                 9843.761 201202                   456788 59.175 -175.8261 58.95 -175.3043    0
5                97910.237 201202                   456832 59.175 -152.8696 58.95 -152.3478    1
6               465625.432 201202                   456833 59.175 -152.3478 58.95 -151.8261    1
sgibb
  • 25,396
  • 3
  • 68
  • 74
Herman Toothrot
  • 1,463
  • 3
  • 23
  • 53
  • I am not able to properly format the table, how do you format a table? – Herman Toothrot Aug 27 '13 at 14:44
  • Are you using the correct separator? If the numbers show ok, then i think you're fine: they are just being printed, but internally they are precise (i guess, but not sure). – Fernando Aug 27 '13 at 15:05
  • Have a look at `?option` especially the `digits` argument (e.g. `option(digits=15)`. – sgibb Aug 27 '13 at 15:07
  • @Fernando yes I am using the correct separator. One quick example is the number 2329.48995 that when imported only shows as 2329.49. I also tried to copy from the df into a single variable and I don't see the decimals. – Herman Toothrot Aug 27 '13 at 15:15
  • @sgibb Ok Thank you it was the same issue. Now I can see all the decimals. So this is just a display option? Meaning that regardless of the numbers of digits displayed, the actual value it's used for calculations. – Herman Toothrot Aug 27 '13 at 15:20
  • yes, it's just a display option. – Ben Bolker Aug 27 '13 at 15:25

1 Answers1

0

using read.table it is easy to specify the parameters of your input csv: sep, quote, dec. Especially using dec you'll specify the character that indicates decimal see for explanation :http://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html

WAF
  • 1,141
  • 20
  • 44