美文网首页
read.table()报错 incomplete final

read.table()报错 incomplete final

作者: Wei_Sun | 来源:发表于2021-11-09 09:35 被阅读0次

    问题

    今天在读取一个.xls文件的时候报错,incomplete final line。

    > dat <- read.table("pca_pop.xls")
    Warning message:
    In read.table("pca_pop.xls") :
      incomplete final line found by readTableHeader on 'pca_pop.xls'
    

    .xls文件另存为.txt,继续报错,line 2 did not have 6 elements。

    > dat2 <- read.table("pca_pop.txt")
    Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
      line 2 did not have 6 elements
    

    解决办法

    1.另存为.csv

    > popinfo <- read.csv("pca_pop.csv")
    > head(popinfo)
      order exp_id vcf_id group   color pch
    1     1      1      1    G2 #9ACD32  16
    2     2      2      2    G2 #9ACD32  16
    3     3      3      3    G2 #9ACD32  16
    4     4      4      4    G2 #9ACD32  16
    5     5      5      5    G2 #9ACD32  16
    6     6      6      6    G2 #9ACD32  16
    

    2.由于数据文件中存在#,被视为注释内容,所以添加comment.char = ""

    > test <-read.table("pca_pop.txt",comment.char = "",header = T)
    > head(test)
      order exp_id vcf_id group   color pch
    1     1      1      1    G2 #9ACD32  16
    2     2      2      2    G2 #9ACD32  16
    3     3      3      3    G2 #9ACD32  16
    4     4      4      4    G2 #9ACD32  16
    5     5      5      5    G2 #9ACD32  16
    6     6      6      6    G2 #9ACD32  16
    

    如有错误敬请指出,引用请注明出处

    相关文章

      网友评论

          本文标题:read.table()报错 incomplete final

          本文链接:https://www.haomeiwen.com/subject/ezrmzltx.html