How can I format my Dates using as.Date() in R?

后端 未结 2 574
余生分开走
余生分开走 2021-01-26 13:48

I have a dataset that looks like this:

Date        AE      AA      AEF     Percent
1/1/2012    1211    1000    3556    0.03
1/2/2012    100     2000    3221    0         


        
相关标签:
2条回答
  • ggplot does not necessarily interpret dates well. Have you tried transforming the data into a timeseries

    Something like:

    # Make data a time series, starting Jan 2009
    data.ts<-ts(data, start=c(2009,1),frequency=52)
    

    Then plot it using ggplot.

    0 讨论(0)
  • 2021-01-26 14:25

    Read help(as.Date) -- you need to supply a format string as well:

    R> as.Date(c("1/1/2001", "1/2/2001", "1/3/2001"), "%m/%d/%Y")
    [1] "2001-01-01" "2001-01-02" "2001-01-03"
    R> 
    
    0 讨论(0)
提交回复
热议问题