read.csv vs. read.table

前端 未结 3 2017
栀梦
栀梦 2021-02-07 05:00

I have seen in several cases that while read.table() is not able to read a tab delimited file (for example the annotation table of a microarray) returning the follo

3条回答
  •  孤独总比滥情好
    2021-02-07 05:46

    read.csv is a fairly thin wrapper around read.table; I would be quite surprised if you couldn't exactly replicate the behaviour of read.csv by supplying the correct arguments to read.table. However, some of those arguments (such as the way that quotation marks or comment characters are handled) could well change the speed and behaviour of the function.

    In particular, this is the full definition of 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, ...)
    }
    

    so as stated it's just read.table with a particular set of options.

    As @Chase states in the comments below, the help page for read.table() says just as much under Details:

    read.csv and read.csv2 are identical to read.table except for the defaults. They are intended for reading ‘comma separated value’ files (‘.csv’) or (read.csv2) the variant used in countries that use a comma as decimal point and a semicolon as field separator.

提交回复
热议问题