Do note the discussion here about:
- Specifying the day of the week
- Ensuring you understand the different ways in which R enumerates weeks of a year
library(dplyr)
library(stringr)
# Using Lubridate per your request
library(lubridate)
tibble(week_year = Missing_day) %>%
mutate(
day_month_year = format(lubridate::parse_date_time(
paste(
str_extract(string = week_year, pattern = "^\\d+"),
str_extract(string = week_year, pattern = "\\d*$"),
'Mon',
sep =
"/"
), 'W/Y/a'
), "%d/%m/%Y")
)
# A tibble: 14 x 2
# week_year day_month_year
# <chr> <chr>
# 1 33/1988 15/08/1988
# 2 37/1991 16/09/1991
# 3 37/1992 14/09/1992
# 4 41/1994 10/10/1994
# 5 15/1997 14/04/1997
# 6 18/2001 30/04/2001
# 7 50/2001 10/12/2001
# 8 16/2002 22/04/2002
# 9 35/2004 30/08/2004
# 10 5/2012 30/01/2012
# 11 50/2012 10/12/2012
# 12 8/2013 25/02/2013
# 13 36/2013 09/09/2013
# 14 51/2017 18/12/2017
# Using Base R
tibble(week_year = Missing_day) %>%
mutate(
day_month_year = format(as.Date(
paste(
1,
str_extract(string = week_year, pattern = "^\\d+"),
str_extract(string = week_year, pattern = "\\d*$"),
sep = "/"
), "%w/%W/%Y"
), "%d/%m/%Y")
)
# A tibble: 14 x 2
# week_year day_month_year
# <chr> <chr>
# 1 33/1988 15/08/1988
# 2 37/1991 16/09/1991
# 3 37/1992 14/09/1992
# 4 41/1994 10/10/1994
# 5 15/1997 14/04/1997
# 6 18/2001 30/04/2001
# 7 50/2001 10/12/2001
# 8 16/2002 22/04/2002
# 9 35/2004 30/08/2004
# 10 5/2012 30/01/2012
# 11 50/2012 10/12/2012
# 12 8/2013 25/02/2013
# 13 36/2013 09/09/2013
# 14 51/2017 18/12/2017