Converting year and month (“yyyy-mm” format) to a date?

后端 未结 7 957
自闭症患者
自闭症患者 2020-11-21 04:55

I have a dataset that looks like this:

Month    count
2009-01  12
2009-02  310
2009-03  2379
2009-04  234
2009-05  14
2009-08  1
2009-09  34
2009-10  2386


        
相关标签:
7条回答
  • 2020-11-21 05:39

    The most concise solution if you need the dates to be in Date format:

    library(zoo)
    month <- "2000-03"
    as.Date(as.yearmon(month))
    [1] "2000-03-01"
    

    as.Date will fix the first day of each month to a yearmon object for you.

    0 讨论(0)
提交回复
热议问题