【问题标题】:Error in read.zoo index has bad entry at data row 2read.zoo 索引中的错误在数据行 2 中有错误条目
【发布时间】:2016-02-22 03:20:11
【问题描述】:

当我使用以下 read.zoo 时,它运行良好,直到我添加了最后一行: (我的来源是 CSV,但这里是用于复制的格式):

library(zoo)
 Lines <- "fdatetime,Consumption
    1,27/03/2015 01:00,0.04
    2,27/03/2015 02:00,0.04"


> z <- read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
Error in read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",") : 
  index has bad entry at data row 51

最后一行有什么问题?如果您删除最后一行,它将起作用!

> data.table::fread(file.choose(), verbose = TRUE)
Input contains no \n. Taking this to be a filename to open
File opened, filesize is 0.000001 GB.
Memory mapping ... ok
Detected eol as \r\n (CRLF) in that order, the Windows standard.
Positioned on line 1 after skip or autostart
This line is the autostart and not blank so searching up for the last non-blank ... line 1
Detecting sep ... ','
Detected 3 columns. Longest stretch was from line 2 to line 30
Starting data input on line 2 (either column names or first row of data). First 10 characters: 1,25/03/20
Some fields on line 2 are not type character (or are empty). Treating as a data row and using default column names.
Count of eol: 51 (including 0 at the end)
Count of sep: 102
nrow = MIN( nsep [102] / ncol [3] -1, neol [51] - nblank [0] ) = 51
Type codes (   first 5 rows): 143
Type codes (+ middle 5 rows): 143
Type codes (+   last 5 rows): 143
Type codes: 143 (after applying colClasses and integer64)
Type codes: 143 (after applying drop or select (if supplied)
Allocating 3 column slots (3 - 0 dropped)
Read 51 rows. Exactly what was estimated and allocated up front
   0.000s (  0%) Memory map (rerun may be quicker)
   0.000s (  0%) sep and header detection
   0.000s (  0%) Count rows (wc -l)
   0.001s (100%) Column type detection (first, middle and last 5 rows)
   0.000s (  0%) Allocation of 51x3 result (xMB) in RAM
   0.000s (  0%) Reading data
   0.000s (  0%) Allocation for type bumps (if any), including gc time if triggered
   0.000s (  0%) Coercing data already read in type bumps (if any)
   0.000s (  0%) Changing na.strings to NA
   0.001s        Total

【问题讨论】:

  • 您是否检查过您的最后一行末尾是否有 \r\n(回车)?可能文件末尾有一两行空行。
  • 以上对我来说不会产生错误(在 Linux 上)。正如@BerndGit 所指出的,问题很可能与原始文件中的回车有关。
  • 可以看出没有回车。我在使用 100 多行时尝试过,问题出在这个特定的行上。其他具有相同格式的文件效果很好。
  • @G. Grothendieck,在这种情况下不需要 header=TRUE
  • this Q&A。与您相同的错误:“index has bad entries at data rows”。来自答案:“引用的行的时间戳与从标准到 DST 的转换一致,因此这些时间在美国东部时区不存在”

标签: r zoo


【解决方案1】:

感谢@Henrik, 解决方法是指定tz,如下:

z<-read.zoo(ts1, tz = "UTC", format = "%d/%m/%Y %H:%M", sep = ",")

【讨论】:

  • 由于问题是切换到夏令时,您可以交替使用 chron 而不是 POSIXct,因为它没有时区或夏令时:library(chron); z &lt;- read.zoo(text = Lines, FUN = as.chron, format = "%d/%m/%Y %H:%M", sep = ",")
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2013-07-13
  • 2015-10-08
  • 1970-01-01
  • 2015-12-21
  • 1970-01-01
  • 2021-04-06
相关资源
最近更新 更多