为什么我的csv文件日期没有通过mdy解析(lubridate)

时间:2014-08-27 20:10:18

标签: r lubridate

我希望有人可以解释为什么lubridate没有正确解析我的日期。我正在读一个相当大的csv文件到数据框,所以我的问题不一定可以重现,但我会展示我的步骤:

    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"

任何接受者?我以前没见过这个。提前谢谢......

0 个答案:

没有答案