在R中,read.csv()和read.csv2()
之间有什么区别官方文件说,
在各种欧洲语言环境中,因为逗号字符用作 小数点,应该使用read.csv2函数
这是什么意思。我觉得在表面上没有任何区别。任何人都可以给出一个具体的例子来进一步澄清它。
答案 0 :(得分:44)
它们(几乎)是相同的功能 - read.table
。唯一的区别是默认参数。看一下源代码:
> 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>
来自doc(请参阅?read.table
):
read.csv
和read.csv2
与read.table
相同,但默认值除外。它们用于读取“逗号分隔值”文件('.csv')或(read.csv2)在使用逗号作为小数点和分号作为字段分隔符的国家/地区中使用的变体。