问题
I'm hoping someone can shed some light on why lubridate isn't parsing my dates correctly. I'm reading in a fairly large csv file to a data frame, so my issue isn't necessarily reproducible, but I'll show my steps:
require("lubridate")
pricingAddy = "C/DailyData.csv"
pricingData = as.data.frame(read.csv(pricingAddy, header = TRUE, stringsAsFactors = FALSE))
sampleHead = head(pricingData)
sampleHead
Symbol TradeDate PX_OPEN PX_HIGH PX_LOW PX_LAST PX_VOLUME MOV_AVG_20D MOV_AVG_50D MOV_AVG_100D MOV_AVG_200D
1 A 1/2/2014 57.10 57.100 56.15 56.21 1916160 56.0765 53.7096 51.5385 47.7321
2 A 1/3/2014 56.39 57.345 56.26 56.92 1866651 56.2435 53.8276 51.6432 47.8032
3 A 1/6/2014 57.40 57.700 56.56 56.64 1777472 56.4005 53.9474 51.7404 47.8781
4 A 1/7/2014 56.95 57.630 56.93 57.45 1463208 56.5315 54.0740 51.8498 47.9591
5 A 1/8/2014 57.33 58.540 57.17 58.39 2659468 56.6980 54.2044 51.9641 48.0454
6 A 1/9/2014 58.40 58.680 57.87 58.41 1757647 56.8515 54.3428 52.0803 48.1284
mdy(sampleHead["TradeDate"])
[1] NA
Warning message:
All formats failed to parse. No formats found.
dts = c("1/2/2014", "1/3/2014", "1/6/2014", "1/7/2014", "1/8/2014", "1/9/2014")
sampleHead["TradeDate"] == dts
TradeDate
1 TRUE
2 TRUE
3 TRUE
4 TRUE
5 TRUE
6 TRUE
mdy(dts)
[1] "2014-01-02 UTC" "2014-01-03 UTC" "2014-01-06 UTC" "2014-01-07 UTC" "2014-01-08 UTC" "2014-01-09 UTC"
Any takers? I haven't seen this before. Thanks in advance...
来源:https://stackoverflow.com/questions/25536111/why-are-my-csv-file-dates-not-parsing-via-mdy-lubridate