Skip to content
Prev 367296 / 398506 Next

converting time format

Hi Lily.
Two problems. You have named the month field "mon" and then refer to
it as "month". Second, as the resolution of as.Date is days, it can't
produce a valid date without specifying the day. Thus:

df.count.mon<-data.frame(count=sample(1:24,24),
 year=rep(2014:2015,each=2),mon=rep(1:12,2))
# make each day the first day of the month
df.count.mon$time<-
 as.Date(paste(df.count.mon$year, df.count.mon$mon,1),
 '%Y %m %d')
df.count.mon
   count year mon       time
1     22 2014   1 2014-01-01
2     12 2014   2 2014-02-01
...
You will get values, but I don't think they are the ones you want.

Jim
On Thu, Feb 23, 2017 at 6:33 AM, lily li <chocold12 at gmail.com> wrote: