datetime - How to extract year and week number using base R? -


i have following data frame:

id   created_at                   year_weak  1     2016-01-01t12:11:03.383z    2016-01  2     2016-01-04t12:11:03.383z    2016-01  3     2016-01-06t12:11:03.383z    2016-01  4     2016-01-11t12:11:03.383z    2016-02  5     2016-01-12t12:11:03.383z    2016-02 

currently have following code using lubridate package:

paste(year(as.date(df$created_at)),week(as.date(df$created_at)),sep = "-") 

i want same thing using base r , how can in base r?

this following works base r commands:

year <- format(as.date(df$created_at)+2, "%y") week <- format(as.date(df$created_at)+2, "%u")  paste(year,week,sep = "-") 

note: have add 2 days, because 1st january 2016 friday , give week of 0. in format() week starts sunday.

regards,
j_f


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -