write.csv:charToDate(x)中的错误:字符串不是标准的明确格式

时间:2013-08-26 20:58:15

标签: r data.table

我正在尝试使用以下结构写入data.table光盘:

Classes ‘data.table’ and 'data.frame':  408776 obs. of  13 variables:
 $ date     : IDate, format: "2013-02-01" "2013-02-01" "2013-02-01" "2013-02-01" ...
 $ hour     : int  1 1 1 1 1 1 2 2 2 2 ...
 $ time     :Class 'ITime'  int [1:408776] 16 186 218 229 463 474 16 186 208 218 ...
 $ bids_med : num  NA NA NA 2.1 2.1 4.6 NA 7.5 7.5 7.5 ...
 $ bids_n   : int  NA NA NA 2 2 2 NA 4 4 4 ...
 $ asks_med : num  NA NA NA 21.5 21.5 21.5 NA 21 21 21 ...
 $ asks_n   : int  NA NA NA 2 2 2 NA 5 5 5 ...
 $ bprice   : num  5 4.2 4.2 4.2 5 5 9 9 9 10 ...
 $ bqty     : int  19 10 10 10 5 5 25 25 50 20 ...
 $ aprice   : num  16 16 21 21 21 21 19 19 19 19 ...
 $ aqty     : int  25 6 50 50 50 50 50 50 50 50 ...
 $ lastprice: num  7 16 16 16 16 16 9 9 9 9 ...
 $ lastqty  : int  31 19 6 6 6 6 25 25 25 25 ...
 - attr(*, "sorted")= chr  "date" "hour" "time"
 - attr(*, ".internal.selfref")= 

我收到以下错误:

> write.csv("data/probit.csv", training, row.names = FALSE)
Error in charToDate(x) : 
  character string is not in a standard unambiguous format

重现:

structure(list(date = structure(c(15737L, 15737L, 15737L, 15737L, 
15737L, 15737L), class = c("IDate", "Date")), hour = c(1L, 1L, 
1L, 1L, 1L, 1L), time = structure(c(16L, 186L, 218L, 229L, 463L, 
474L), class = "ITime"), bids_med = c(NA, NA, NA, 2.1, 2.1, 4.6
), bids_n = c(NA, NA, NA, 2L, 2L, 2L), asks_med = c(NA, NA, NA, 
21.5, 21.5, 21.5), asks_n = c(NA, NA, NA, 2L, 2L, 2L), bprice = c(5, 
4.2, 4.2, 4.2, 5, 5), bqty = c(19L, 10L, 10L, 10L, 5L, 5L), aprice = c(16, 
16, 21, 21, 21, 21), aqty = c(25L, 6L, 50L, 50L, 50L, 50L), lastprice = c(7, 
16, 16, 16, 16, 16), lastqty = c(31L, 19L, 6L, 6L, 6L, 6L)), .Names = c("date", 
"hour", "time", "bids_med", "bids_n", "asks_med", "asks_n", "bprice", 
"bqty", "aprice", "aqty", "lastprice", "lastqty"), sorted = c("date", 
"hour", "time"), class = c("data.table", "data.frame"), row.names = c(NA, 
-6L))

我很遗憾该怎么办。有什么建议可能有帮助吗? THX。

1 个答案:

答案 0 :(得分:6)

你刚才有write.csv的参数乱序。如果按位置传递,则首先是data.frame或data.table,然后是文件名。你也可以写file = first:

write.csv(file="out.csv",training,row.names=FALSE)

write.csv(training,"out.csv",row.names=FALSE)