r - R 中 read.csv() 和 read.csv2() 之间的区别

标签 r csv read.csv

在 R 中,read.csv() 和 read.csv2() 有什么区别

官方文档说,

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

这是什么意思。从表面上看,我没有看到任何区别。任何人都可以给出一个具体的例子来进一步澄清它。

最佳答案

它们(几乎)是相同的函数 - 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.csvread.csv2read.table 相同。它们用于读取“逗号分隔值”文件(“.csv”)或(read.csv2),这是在使用逗号作为小数点和分号作为字段分隔符的国家/地区使用的变体。

关于r - R 中 read.csv() 和 read.csv2() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22970091/

相关文章:

c++ - 使用 C++ iostreams 解析具有空值的 CSV

powershell - 如何使用 PowerShell 检查 csv 列中的空行

r - 从已知百分位数生成正态分布

PowerShell 导入-CSV "filter out blank rows"导出-CSV

r - 在R中同时比较多个向量?

r - 将 JSON 转换为数据帧/CSV 时需要导航列表方面的帮助

r - 导入 read.csv/read.xlsx 时将 NA 值插入数据框空白单元格

R 中的 read.csv 阅读日期不同

r - R 中的逻辑索引失败

r - install.packages R 在 Ubuntu 12.04 上下载但不安装包