问题
The data looks like
Time Set1 Set2
10:19:38.551629 16234 16236
10:19:41.408010 16234 16236
10:19:47.264204 16234 16236
I am trying to load this into zoo.
orig <- read.zoo("~/sample.txt",sep="",header=TRUE,index.column=1,format="%H:%M:%S.%6f")
Error in read.zoo("~/sample.txt", sep = "", header = TRUE, index.column = 1, :
index has 3 bad entries at data rows: 1 2 3 ...
I have checked all the relevant posts 1. R issue with rounding milliseconds 2. Milliseconds puzzle when calling strptime in R 3. How to parse milliseconds in R?
However this does not help. Any Suggestions
回答1:
You want the index to be a time class such as POSIXct
or POSIXlt
. Also, your format
argument wasn't quite right. Try this
read.zoo("~/sample.txt", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)
Which, for the sample data provided, gives
read.zoo(text=" Time Set1 Set2
10:19:38.551629 16234 16236
10:19:41.408010 16234 16236
10:19:47.264204 16234 16236 ", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)
# Set1 Set2
#2012-06-21 10:19:38.551629 16234 16236
#2012-06-21 10:19:41.408010 16234 16236
#2012-06-21 10:19:47.264204 16234 16236
来源:https://stackoverflow.com/questions/11136340/zoo-xts-microsecond-read-issue