Difference between read.table and read.delim functions

只愿长相守 提交于 2019-12-03 04:38:34

问题


What is the difference between the read.table() and read.delim() functions in the R language?


回答1:


In addition to reading help pages when you are unsure of what a function does, you can also examine the function's actual code. For example, entering read.delim reveals that the function contains the following code:

> 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, ...)

Thus, read.delim() is simply a wrapper function for read.table() with default argument values that are convenient when reading in tab-separated data. It is exactly the same as calling:

read.table(file, header = TRUE, sep = "\t", quote = "\"", 
    dec = ".", fill = TRUE, comment.char = "")



回答2:


From R help:

Similarly, read.delim and read.delim2 are for reading delimited files, defaulting to the TAB character for the delimiter. Notice that header = TRUE and fill = TRUE in these variants, and that the comment character is disabled.



来源:https://stackoverflow.com/questions/10599708/difference-between-read-table-and-read-delim-functions

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