Difference between read.csv() and read.csv2() in R

允我心安 提交于 2019-11-27 13:24:48

问题


In R , what is the difference between read.csv() and read.csv2()

The official documentation says,

In various European locales, as the comma character serves as the decimal point, the function read.csv2 should be used instead

What does this mean. I don't see any difference at the superficial level. Can anybody give out a concrete example to clarify it further.


回答1:


They are (almost) the same functions - read.table. The only difference is default parameters. Look at source code:

> read.csv
function (file, header = TRUE, sep = ",", quote = "\"", dec = ".", 
    fill = TRUE, comment.char = "", ...) 
read.table(file = file, header = header, sep = sep, quote = quote, 
    dec = dec, fill = fill, comment.char = comment.char, ...)
<bytecode: 0x5e3fa88>
<environment: namespace:utils>
> read.csv2
function (file, header = TRUE, sep = ";", quote = "\"", dec = ",", 
    fill = TRUE, comment.char = "", ...) 
read.table(file = file, header = header, sep = sep, quote = quote, 
    dec = dec, fill = fill, comment.char = comment.char, ...)
<bytecode: 0x5c0a330>
<environment: namespace:utils>

From doc (see ?read.table):

read.csv and read.csv2 are identical to read.table except for the defaults. They are intended for reading ‘comma separated value’ files (‘.csv’) or (read.csv2) the variant used in countries that use a comma as decimal point and a semicolon as field separator.



来源:https://stackoverflow.com/questions/22970091/difference-between-read-csv-and-read-csv2-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!