Cannot read file with “#” and space using read.table or read.csv in R

前端 未结 1 1610
失恋的感觉
失恋的感觉 2020-12-10 10:47

I have a file where the first row is a header. The header can have spaces and the # symbol (there may be other special characters as well). I am trying to read this file usi

相关标签:
1条回答
  • 2020-12-10 11:36

    From the documentation (?read.csv):

    comment.char character: a character vector of length one containing a single character or an empty string. Use "" to turn off the interpretation of comments altogether.

    The default is comment.char = "#" which is causing you trouble. Following the documentation, you should use comment.char = "".

    Spaces in the header is another issue which, as mrdwab kindly pointed out, can be addressed by setting check.names = FALSE.

    chromosomes <- read.csv(chromFile, sep = "\t", skip = 0, header = TRUE,
                            comment.char = "", check.names = FALSE)
    
    0 讨论(0)
提交回复
热议问题