R语言中的read.table()
和read.delim()
函数之间有什么区别?
答案 0 :(得分:20)
除了在不确定函数的功能时阅读帮助页面,您还可以检查函数的实际代码。例如,输入read.delim
会显示该函数包含以下代码:
> read.delim
function (file, header = TRUE, sep = "\t", quote = "\"", dec = ".",
fill = TRUE, comment.char = "", ...)
read.table(file = file, header = header, sep = sep, quote = quote,
dec = dec, fill = fill, comment.char = comment.char, ...)
因此,read.delim()
只是read.table()
的包装函数,其默认参数值在读取制表符分隔数据时很方便。它与调用完全相同:
read.table(file, header = TRUE, sep = "\t", quote = "\"",
dec = ".", fill = TRUE, comment.char = "")
答案 1 :(得分:4)
来自R帮助:
同样,read.delim和read.delim2用于读取分隔文件,默认为分隔符的TAB字符。请注意,这些变体中的header = TRUE和fill = TRUE,并且注释字符已禁用。