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

后端 未结 7 980
自闭症患者
自闭症患者 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:37

    Since dates correspond to a numeric value and a starting date, you indeed need the day. If you really need your data to be in Date format, you can just fix the day to the first of each month manually by pasting it to the date:

    month <- "2009-03"
    as.Date(paste(month,"-01",sep=""))
    

提交回复
热议问题