r - 写入.csv : Error in charToDate(x) : character string is not in a standard unambiguous format

标签 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))

我完全不知道该怎么办。有什么建议可以帮助吗?谢谢。

最佳答案

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

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

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

关于r - 写入.csv : Error in charToDate(x) : character string is not in a standard unambiguous format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18452907/

相关文章:

引用另一个表中的列名以插入共享 ID 中的值

r - 如何在 R 中制作时间序列箱线图

r - R中的多元偏斜正态

r - 将具有相似名称的列相乘

r - 非对等连接的结果中的顺序是如何确定的?

r - 如果一列的值出现在另一列中,则对行进行分组

r - 如何查找两个数据帧之间不相同的值的数量

r - acos(1)返回NaN的某些值,而不是其他值

r - 使用 data.table 按组显示重复项

r - 聚合/总结每组多个变量(例如总和、平均值)