barplot failure in R 3.1.0. read.csv converting what should be numerics to factors

前端 未结 2 670
粉色の甜心
粉色の甜心 2020-12-21 22:11

I have a little problem with the bar plot function of R 3.1.0. (it works fine in older versions).

nd_p_a<- read.csv(\"nd_p_a.csv\")
barplot(nd_p_a$y, col=         


        
相关标签:
2条回答
  • 2020-12-21 22:33

    There seems to be an issue with the new version (3.1.0) of type.convert() which gets called by read.table() which gets called by read.csv() in R. The most recent version of type.convert() assumes that the representation in your file is more accurate than R's internal numeric storage format (double-precision floating point values) and thus casts it to a FACTOR. This behavior appears very surprising to a bunch of people, so I would bet it will go away, or there will be a parameter that will be able to be passed to type.convert() through the chain. It seems sufficiently painful for people (including myself) that rely on the old-standing behavior of the automatic field type detection algorithm.

    This question should be cross-linked somewhere upstream to something like "Why doesn't read.csv() work reliably with floating point values anymore?"

    http://r.789695.n4.nabble.com/type-convert-and-doubles-td4688616.html

    0 讨论(0)
  • 2020-12-21 22:37

    Here is a work around. The new behavior is annoying

    read.csv("nd_p_a.csv", colClasses=c("numeric", "numeric"))
    
    0 讨论(0)
提交回复
热议问题