【问题标题】:function 'read.table' and error函数“read.table”和错误
【发布时间】:2014-07-21 22:59:56
【问题描述】:

这是我的“*.txt”数据

ID    LBI   RTI  WDI FLA  PSF  FSF ZDF1 PROZD
ar      ?,35.30,2.60,  ?,42.4,24.2,47.1,69
arn  1.23,27.00,3.59,122, 0.0,40.0,40.0,30
be   1.24,26.50,2.90,121,16.0,20.7,29.7,72
bi1  1.07,29.10,3.10,114,44.0, 2.6,26.3,68
bi2  1.08,43.70,2.40,105,32.6, 5.8,10.7,42
bie  1.39,29.50,2.78,126,14.0, 0.0,50.0,78
bn   1.31,26.30,2.10,119,15.7,15.7,30.4,72
bo   1.27,27.60,3.50,116,16.8,23.0,35.2,69
by   1.11,32.60,2.90,113,15.8,15.8,15.0,57

然后,当我命令时它失败了

r2 <- read.table('StoneFlakes.txt',header=TRUE,na.strings='?')

错误;

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 1 did not have 9 elements

有人可以帮助我吗?

【问题讨论】:

  • @germcd:前两列不是','
  • @JoshuaUlrich - 标题根本没有, 分隔符。
  • 你可能想把readLines("yourFile.txt")的前几行贴出来,问题出在哪里还不是很清楚。

标签: r


【解决方案1】:

使用

text <- readLines('StoneFlakes.txt')
text <- gsub(",", " ", text)
read.table(textConnection(text), header=TRUE, na.strings='?')
  #insted of using textConnection you can also use
read.table(text=text, header=TRUE, na.strings='?')

【讨论】:

    猜你喜欢
    • 2021-11-17
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 2013-10-26
    • 2014-04-30
    • 1970-01-01
    相关资源
    最近更新 更多