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
Post a Comment