I have the following columns' names of dataframe in year/week format
cols = colnames(vci1981.df)
[1] "gid" "xcoord" "ycoord" "col" "row" "gwno" "country" "km2" "1981035" "1981036"
[11] "1981037" "1981038" "1981039" "1981040" "1981041" "1981042" "1981043" "1981044" "1981045" "1981046"
[21] "1981047" "1981048" "1981049" "1981050" "1981051" "1981052"
Note: year 1981- week 0xx
How can I transform them into the corresponding year-month format please ?
Example: 1981-035 = 1981-08
I tried the same method as here Transform year/day colnames into date in r without success.
cols = ymd(parse_date_time(cols[9:length(cols)], orders="yw"))
I got NA here.
and
cols = as.Date(cols[9:length(cols)], "%Y%W")
I got non corresponding values here: [1] "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" [9] "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" "1981-06-29" [17] "1981-06-29" "1981-06-29"