Convert week number to date

后端 未结 4 605
离开以前
离开以前 2020-11-28 11:30

I have a data frame in R with the week of the year that I would like to convert to a date. I know I have to pick a year and a day of the week so I am fixing those values at

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 12:05

    as.Date is calling the 1 to 9 as NA as it is expects two digits for the week number and can't properly parse it.

    To fix it, add in some - to split things up:

    as.Date(paste(2014, df$Week, 1, sep="-"), "%Y-%U-%u")
    

提交回复
热议问题