r - Find month from week numbers using lubridate -
i have list of dates:
library(lubridate) my.dates = ymd(c("2013-12-14", "2014-01-18", "2014-01-27", "2013-12-13", "2013-12-29", "2013-12-06")) the following lubridate::weekfunctions outputs numeric vector when convert these dates week numbers:
week(my.dates) [1] 50 3 4 50 52 49 can lubridate output date ("posixct" "posixt") object converts my.dates week number , year number. output should date object (not character or numeric vector) formatted this:
[1] "50-2013" "3-2014" "4-2014" "50-2013" "52-2013" "49-2013" i'm interested in solution uses lubridate.
in response comments question, question has changed number of times @ moment requested input my.dates , output of form week-year (and not described in subject of question).
to convert my.dates week-year format try following week , year lubridate functions:
> paste(week(my.dates), year(my.dates), sep = "-") [1] "50-2013" "3-2014" "4-2014" "50-2013" "52-2013" "49-2013" the sample output in question did not use leading zeros on week if leading zeros desired on week then:
> sprintf("%02d-%d", week(my.dates), year(my.dates)) [1] "50-2013" "03-2014" "04-2014" "50-2013" "52-2013" "49-2013" note requirement output posixt class object , of format week-year contradictory since format representation character object , not property of posixt class objects themselves. noted in comments question, week-year not uniquely identify date.
Comments
Post a Comment