[datatable-help] Apparent loss of decimals when reading a numeric column with fread() !
Bacou, Melanie
mel at mbacou.com
Tue Aug 4 11:39:34 CEST 2015
Hi,
something very strange today as I'm trying to simply read in the
attached CSV into R (it's small).
I seem to be losing all decimals in the last column. I tried to set
`colClasses`, but made no difference.
Not sure what's wrong with me today!
Can any one replicate? I suppose it's in the input file, will keep digging.
Thx, --Mel.
E.g. this is what I see when opening the CSV in emacs:
And then this is what shows up in R:
```r
pcn <- fread("PovCalServlet_15.08.03.csv")
sapply(pcn, class)
# country povLine mean hcr gap sev
# "character" "numeric" "numeric" "numeric" "numeric" "numeric"
# watts popM yearNum
# "numeric" "numeric" "numeric"
# => looks as expected, but then no decimal...
pcn08$yearNum
# [1] 2008 2012 2009 2009 2006 2008 2007 2008 2011 2004 2006 2011 2008
2010 2005
# [16] 2003 2006 2008 2007 2012 2002 2005 2010 2007 2010 2010 2010 2008
2008 2012
# [31] 2006 2009 2010 2011 2010 2011 2010 2011 2006 2011 2011 2009 2010
2012 2011
# [46] 2008 2012 2009 2010 2008 2012 2009 2009 2006 2008 2007 2008 2011
2004 2006
# [61] 2011 2008 2010 2005 2003 2006 2008 2007 2012 2002 2005 2010 2007
2010 2010
# [76] 2010 2008 2008 2012 2006 2009 2010 2011 2010 2011 2010 2011 2006
2011 2011
# [91] 2009 2010 2012 2011 2008 2012 2009 2010
sessionInfo()
# R version 3.2.1 (2015-06-18)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
#
# locale:
# [1] LC_COLLATE=English_United States.1252
# [2] LC_CTYPE=English_United States.1252
# [3] LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C
# [5] LC_TIME=English_United States.1252
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] rgdal_1.0-4 sp_1.1-1 data.table_1.9.4 rj_2.0.3-2
#
# loaded via a namespace (and not attached):
# [1] magrittr_1.5 plyr_1.8.3 tools_3.2.1 rj.gd_2.0.0-1
# [5] reshape2_1.4.1 Rcpp_0.11.6 stringi_0.5-5 grid_3.2.1
# [9] stringr_1.0.0 chron_2.3-47 lattice_0.20-33
```
--
Melanie BACOU
International Food Policy Research Institute
Snr. Program Manager, Spatial Data and Analytics
Work +1(202)862-5699
E-mail m.bacou at cgiar.org
Visit www.harvestchoice.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150804/be45dc03/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dhechbei.png
Type: image/png
Size: 20307 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150804/be45dc03/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PovCalServlet_15.08.03.csv
Type: text/csv
Size: 5716 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150804/be45dc03/attachment-0001.csv>
More information about the datatable-help
mailing list