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

时间:2016-01-19 09:15:57

标签: r

我有一个名为sales_df的data.table,例如:

library(data.table)
dput(head(sales_df) 
sales_df <- structure(list(OrderID = c(101517L, 101629L, 101651L, 106402L, 
109324L, 110779L), CustID = c(1015L, 1005L, 1012L, 1020L, 1005L, 
1020L), CustName = c("OOO_CUST", "EEE_CUST", "LLL_CUST", "TTT_CUST", 
"EEE_CUST", "TTT_CUST"), OrderDT = structure(c(14610, 14610, 
14610, 14610, 14610, 14610), class = "Date"), EmpID = c(1005L, 
1016L, 1009L, 1015L, 1014L, 1016L), EmpName = c("EEE_EMP", "PPP_EMP", 
"III_EMP", "OOO_EMP", "NNN_EMP", "PPP_EMP"), PrdID = c(1003L, 
1005L, 1004L, 1001L, 1009L, 1008L), PrdName = c("IPHONE5", "IPHONE6", 
"IPHONE5S", "IPHONE3", "GALAXY5", "GALAXY4 PLUS"), FQty = c(600, 
700, 650, 400, 600, 550), UnitPrice = c(10000, 11000, 11000, 
7000, 10000, 11000), Amount = c(6, 6.3, 7.8, 4.8, 6, 5.5), Year = c(2010, 
2010, 2010, 2010, 2010, 2010), Month = c(1, 1, 1, 1, 1, 1)), .Names = c("OrderID", 
"CustID", "CustName", "OrderDT", "EmpID", "EmpName", "PrdID", 
"PrdName", "FQty", "UnitPrice", "Amount", "Year", "Month"), class = c("data.table", 
"data.frame"), row.names = c(NA, -6L))

当我尝试总结我的数据时,我碰巧遇到了这个问题

sales_summary_by_month <- sales_df %>% group_by(Year, Month) %>%
  summarize(nth = n(),
            total = sum(Amount)) %>%
  mutate(YM = as.Date(paste(Year,Month,1,sep="-")))

Error in charToDate(x) : 
  character string is not in a standard unambiguous format

0 个答案:

没有答案