在 R 中,read.csv() 和 read.csv2() 有什么区别
官方文档说,
在各种欧洲语言环境中,由于逗号字符用作小数点,因此应使用函数 read.csv2 代替
这是什么意思。从表面上看,我看不出有什么不同。任何人都可以给出一个具体的例子来进一步澄清它。
它们(几乎)是相同的功能 - 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>
来自文档(参见?read.table
):
read.csv
并且除了默认值外read.csv2
都相同。read.table
它们用于读取“逗号分隔值”文件 ('.csv') 或 (read.csv2) 在使用逗号作为小数点和分号作为字段分隔符的国家/地区使用的变体。