Warm tip: This article is reproduced from serverfault.com, please click

Find the first day of the x week of the x year

发布于 2020-11-29 01:06:08

Is there a way to find the first day of the x week of the x year with the package lubridate?

For example I have this data: week number in some year (e.g 33th week from the year 1988) and i would like to convert it into a data like: day/month/year (e.g 15/08/1988).

Missing_day <- c("33/1988", "37/1991", "37/1992", 
             "41/1994", "15/1997", "18/2001", 
             "50/2001", "16/2002", "35/2004", 
             "5/2012", "50/2012", "8/2013", 
             "36/2013", "51/2017")

thanks

Questioner
Ian.T
Viewed
0
Ronak Shah 2020-11-29 09:11:44

You can attach the weekday and convert the data into Date. Using base R, you can do :

as.Date(paste0('1/', Missing_day), '%u/%U/%Y')

# [1] "1988-08-15" "1991-09-16" "1992-09-14" "1994-10-10" "1997-04-14"
# [6] "2001-05-07" "2001-12-17" "2002-04-22" "2004-08-30" "2012-01-30"
#[11] "2012-12-10" "2013-02-25" "2013-09-09" "2017-12-18"