Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between read.table and read.delim functions

Tags:

r

read.table

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

like image 425
user1021713 Avatar asked May 15 '12 11:05

user1021713


2 Answers

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 = "")
like image 77
jthetzel Avatar answered Oct 15 '22 20:10

jthetzel


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.

like image 38
teucer Avatar answered Oct 15 '22 22:10

teucer